Skip to content

KBEngine Coding Pitfalls and Lint Rules ​

Kode distinguishes engine constraints, explanatory editor hints, and implemented lint diagnostics. A type appearing in hover or inlay hints does not mean a corresponding misuse check exists.

The detailed rule catalog records the source symbols, examples, implementation status, and known analysis limits. The source review used Kode bf26cbf and KBEngine f85ad81; the hasattr correction is in Kode c351606.

AreaImplemented behaviorLimits
Optional EntityCall receiverskbengine.receiverNone reports unguarded self.cell/base/client member uses as WarningsGuard analysis is heuristic; aliases, nested exits, compound conditions and lexical filtering still have gaps
Attribute existencehasattr(self, "cell") no longer suppresses the None warningThe getter may exist while returning None; check the returned value
RPC routingkbengine.sectionMismatch compares known declarations with receiver sectionsUnknown declarations cannot establish a mismatch; adding a None guard does not fix routing
.def structure and scalar valuesType, Flags, DetailLevel, duplicates and required fields have checksOn-demand analysis suggestions are separate from diagnostics on edit
Readonly attributes and role restrictionskbengine.readOnlyWrite reports writes to engine readonly properties; kbengine.roleMisuse reports self.<property> uses whose registered face set (baseapp/cellapp/client) does not include the current script's face, citing the registering face's engine sourceAssignment checks and property wrong-role checks are implemented; wrong-role API (method) checks remain hint-only until a role table for methods exists
RPC argument misuse and lifecycle hazardskbengine.rpcArgCount reports a call-site argument count that definitely mismatches the .def method's <Arg> count for the routed section (star-args, dynamic receivers, out-of-section declarations and declaration-not-ready stay unknown); kbengine.rpcArgType reports a call-site argument whose literal form definitely cannot serialize as the declared <Arg> builtin type family of the routed section — the integer family packs 0 on a failed conversion (datatype.h:875-898), FLOAT/DOUBLE/STRING/UNICODE log a TypeError and leave the argument out of the stream so the remote side reads misaligned bytes (datatype.cpp:540-549/1050-1062), BLOB accepts only bytes (datatype.cpp:1448-1468) and VECTOR reads components through the sequence protocol (datatype.cpp:841-856); kbengine.postDestroy reports a self.<member> access (excluding identity/state items and destroy) that a determinable same-block self.destroy() precedes within one functionType checks judge only statically determinable literal forms (numbers, strings/bytes, bool/None, list/dict/set/tuple, Vector2/3/4(...) constructor calls); names, plain calls and non-literal forms stay unknown, list/tuple arguments to VECTOR stay unknown (structurally feasible), PYTHON/PY_DICT/PY_LIST (pickle) and ENTITYCALL never claim, types.xml aliases/ARRAY/FIXED_DICT are not resolved (no claim); cross-line calls contribute no spans, and count mismatches stay with kbengine.rpcArgCount; post-destroy covers only the determinable same-function same-block core (conditional destroys, cross-callback/cross-block flows, exceptions and def-declared destroy are never guessed)
cellData known-field writeskbengine.cellDataWriteType validates a whole-line literal assignment to a known self.cellData["<key>"] field against the declared engine scalar structure and range (datatypes.cpp registry) and reports the actual/expected types with the declaration sourceUnknown keys, non-scalar types (PYTHON family/ARRAY/FIXED_DICT/custom aliases), non-literal or cross-line right-hand sides and unknown-element vector components stay unreported; alias receivers follow the latest-assignment rule and are skipped after rebinding
FIXED_DICT construction siteskbengine.fixedDictConstruct validates a whole dict literal assigned to a FIXED_DICT-typed target (self.<prop> = {…} / self.<prop>["<key>"]… = {…}, key chains reuse the STRUCT-02 resolver) against the types.xml declared field set — with all-literal keys and no ** spread/dynamic keys, missing fields are reported at the opening brace; a literal key outside the declared set is reported at the key span (even when the universe is open); a builtin-scalar field's literal value is judged for structure mismatch against the same CELL-08 engine scalar truthPlain dicts (bare-name targets, unresolvable or non-FD property types, augmented assignment, comparisons, call RHS) are never constrained; scalar ranges stay with the range lane; nested dict literals are not descended
def-property scalar assignmentskbengine.scalarAssign judges a whole-line literal assigned to a target resolving to an engine scalar — self.<prop> = <literal> (root face, alias chains drilled through the types.xml aliasType registry chain), self.<prop>["<key>"]… = <literal> (FD-field face, last key via the STRUCT-02 resolver) and self.<prop>[<int>] = <literal> (array-element face, element type from the inline of node) — for structure mismatch and integer range against the same CELL-08 engine scalar truthNever judges from Python type names (registry-level resolution only); name/call RHS, augmented assignment, ==, unresolvable properties, FD containers, array FD elements, unknown keys and mixed chains (array element then key) decline honestly; dict literals stay with the construction face
types.xml alias integritykbengine.types.* (eight codes) mirror the engine's single-pass ordered types.xml load (datatypes.cpp:105-187): forward references/cycles and element-form directives that read as an empty type (kbengine.types.forwardRef), _ reserved prefixes (kbengine.types.reservedPrefix), case-insensitive redefinitions where the engine logs but the first registration wins (kbengine.types.duplicateAlias, Warning), ARRAY <of> sibling-chain gaps / nested arrays missing the next <of> / unknown or FIXED_DICT-keyword targets (kbengine.types.arrayOf), FIXED_DICT missing <Properties> or zero loadable fields — "no keys" (kbengine.types.fixedDictStructure), field types resolving to nothing (kbengine.types.fieldType) and Type-less fields the engine silently drops (kbengine.types.fieldNoType, Warning), and FIXED_DICT fields whose type or ARRAY element chain ends at ENTITYCALL (kbengine.types.fdEntityCallPersistent, Warning — the engine silently clears the field's persistence; the explicit close-out is the case-sensitive literal false)The check keeps scanning after a fatal entry so all findings surface at once, but a failed entry never enters the simulated registry — the bookkeeping mirrors the engine load order and later references are still judged by document order; name resolution is exact-case (engine getDataType/dataTypes_), with a case-variant hint when a near-miss name exists; attribute-form entries the extension's own def parser tolerates are rejected here per engine truth (empty entries are silently skipped by the engine); unparseable XML yields zero findings
Silent persistence loss on ENTITYCALL propertieskbengine.persistentEntityCall reports a .def property declaring <Persistent>true</Persistent> whose type — through the types.xml alias chain — resolves to ENTITYCALL: the PropertyDescription constructor silently clears isPersistent with no log (property.cpp:48-51), so the field stops persisting while the def claims otherwise

| alias.xml alias integrity (KODE-SYN-003) | The same eight kbengine.types.* codes run on alias.xml documents in registry-preload mode: the workspace types.xml registry names are preloaded into the simulated registry before judging (engine single-pass load order — types.xml first, alias.xml second), so an alias entry resolves against builtins + types.xml names + in-document earlier entries; the cursor's own entry stays outside the resolvable domain (the engine reads the directive before registering it) and _-prefixed preloads are skipped (validTypeName rejects them before registration); editing assist rides the same document selector — completion at a target-value position lists builtins + in-document earlier entries + types.xml registry names, definition jumps to in-document entry ranges or types.xml declaring lines, builtin targets decline | A duplicate against types.xml keeps first-wins: the original stays in the table and later references still resolve to it (engine addDataType rejects re-registration), reported only as kbengine.types.duplicateAlias; composite preloaded names (ARRAY/FIXED_DICT) share the in-document behavior — the chain-end walk yields no ENTITYCALL verdict for them; unparseable XML yields zero findings | Inline ARRAY properties never trigger the check (the engine judges the property's own type name, which is the ARRAY form); a missing or non-true <Persistent> (case-insensitive true, per entitydef.cpp:1181-1187) means the engine never enables persistence, so there is no gap to report; broken or cyclic alias chains are treated as unresolvable and stay silent | | Behavior-knowledge pipeline (KB-001) | kbengine.fixedDictNestedMutation reports FIXED_DICT property sub-key assignment (Warning + whole-reassign quick fix); kbengine.destroyedEntityReference reports self stored into a module-level container (Warning); kbengine.timerCleanupOnDestroy reports redundant delTimer inside onDestroy (Information — destroy() already cancels all timers) | The three rules publish to the dedicated kbengine-trap-lints collection with per-rule toggles; only statically determinable single-line patterns are analyzed — closure escape, cross-block flows and multi-line statements are never guessed | | Entity reference caching | kbengine.entityReferenceCache warns when a Python-layer entity reference outlives destroy and blocks the engine from releasing the entity (registry strong ref already dropped; entity_garbages logs only after 3600s): class attributes, module-level containers and engine-timer closures, with a quick fix that stores entity.id instead; downstream reads must be updated by the user | Only statically provable seeds are analyzed — the four lifecycle-hook entity parameters, KBEngine.entities.get/[] queries and assignment chains; self.addTimer (safe per KB-001), createEntity* results, .id reads, bare names, dynamic calls and loop targets are never reported |

EntityCall values can be None ​

KBEngine registers EntityCall getters as attributes. The getter can return None when the peer is absent, including before creation or after losing the peer. Therefore attribute existence is insufficient:

python
if hasattr(self, "cell"):
    self.cell.send()  # Still warns: the getter can return None.

Check the value instead:

python
if self.cell is not None:
    self.cell.send()

This checks local None risk; it does not guarantee remote delivery or execution.

Python receiver checks are enabled by kbengine.receiverNoneDiagnostics. The existing document scheduler publishes results to Problems. Disabling the setting suppresses diagnostics without changing engine behavior. New rules must share versioned parsing, avoid executing user Python, support cancellation and large-file yielding, and include both unsafe and legal examples before being marked complete.

Kode documentation