Skip to content

Ground project lookups, refuse relationship names as field values, log per-request cost (refs #3706, #3704; closes #3705) - #3709

Merged
malibio merged 2 commits into
mainfrom
issue-3706-grounding-remaining
Oct 10, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-3706-grounding-remaining

Conversation

@malibio

@malibio malibio commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

What

Follow-up to the grounding work already merged. Measured on the local model (gemma-4-e4b-q4km), 3 reps per scenario.

Measured (local model, bun run eval:grounding, 3 reps)

Run Result
Before these changes, 7 scenarios (two new) 4/7 (stale daemon for the two write/project cases, see note)
After #3705 refusal 6/7: assign 3/3, project 0/3 (answer replaced by the id guard)
After id grounding + lookup routing 6/7: project 3/3, assign 3/3; status-of-assigned 0/3

status-of-assigned finds the right two tasks and the tool result carries open / in_progress; the model writes "which has started today" for the second. That is the 4B model paraphrasing a value, not a context gap, and it passed on the larger query-route prompt.

Not done here

Remote-model measurements (reasoning and non-reasoning) need an OpenRouter key in the isolated daemon's database; the harness only drives a loaded local model.

Test plan

  • bun run test:changed passes; new tests: relationship-as-field refusal and the create_relationship call it names, resolved-entity grounding, override cases both ways, project links, request-size/reasoning-token parsing.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y6xprEu6D5YSLfMUWqZsoj

@malibio

malibio commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

Net positive. The relationship-key refusal is a sound, narrowly scoped fix (refuse rather than rewrite, because the edge needs an id a field value doesn't carry). The mentioned-entity grounding is small and correct. The main risks are in the routing widening, where the write-word exclusion is a closed list that fails open in the unsafe direction, and in test coverage for the false-refusal escape hatch. No Sync-boundary, issue-number or lint-suppression violations found in the diff.

Verdict: APPROVE with improvements (no blockers).

Findings

🔴 Critical

None.

🟡 Improvements

  • routing.rs asks_for_a_write (~line 408) and asks_what_the_workspace_holds unmarked paths. A misroute here removes write tools for the turn, and the closed 17-word list fails open. Verbs that clearly ask for a change but are absent: complete, finish, fix, edit, tag, schedule, reschedule, cancel, approve, put, send, start, save, write, record, log, copy, merge, restore, delete is there but trash is not. Example: "Please list the tasks, then complete the old ones" or "Tell me what is due Friday and reschedule it" has no question mark, passes every guard, and becomes a read-only Lookup. The pre-existing marked path has the same gap, but the new unmarked paths widen the exposure and are the ones that rely on this list as the only safeguard. Suggestions, either: (a) extend the list (cheap), or (b) make the unmarked "polite" branch stricter: require the whole message to contain no verb outside a small read-verb set (list/show/find/search/look/check/tell/let/know/what/how/which/who/when/...) - an allowlist fails closed. Also note the list is English-only while the marked path accepts the full-width ? (CJK). Add negative tests for at least complete, reschedule, and a conjunction case ("... and then ...").
  • routing.rs "how many"/"how much" path. counts bypasses the "asks for a write" check only through !asks_for_a_write(&words), so "How many tasks are open, finish the old ones" misroutes for the same reason. Same fix as above.
  • tools.rs ~3925-3950 (refuse_relationship_keys), built-in inbound names. For a key like child_of, has_member, mentioned_by or role_of, resolve_hop returns source_type: None with HopDirection::Inbound and the forward name. The code picks the None arm and tells the model "from_id the '{node_type}' node's id", which is the wrong direction for an inbound hop (it would create an edge from this node when the node is the to side). Branch on hop.direction as well as source_type, or restrict the refusal to hops that are declared on a schema and let built-ins fall through.
  • tools.rs, tests for the escape hatch. The doc comment names the false-refusal scenario (a user's incident-report type with a declared resolved field while another type's relationship reaches reports under that name), but no test covers it: the only new integration test refuses undeclared keys on update_node. Add (1) a test that a declared field with a relationship-colliding name is stored, not refused (fails if the declares_field check is removed), and (2) a create_node refusal test (that call site is untested; removing the line at the create_node call site would leave the suite green). Also (3) the custom:-prefixed declared field case: declares_field is asked with the stripped name, which is right for custom: user types per ADR-063 but is not pinned.
  • tools.rs, declares_field(...).unwrap_or(false). On an error reading the schema the code treats the key as undeclared and may then refuse a legitimate field. Failing open (skip the refusal on error, as the relationship_named let Ok(Some(..)) else continue already does) is consistent and safer for a guard that is advisory.
  • Duplicated size computation: inference.rs (~91-130) vs openai_compat_inference.rs RequestSizes::of. Same system/conversation split, same per-tool name+description+schema sizing, same top-3 largest_tools formatting, written twice (DRY). The tested version lives only in the OpenAI file, so the local copy is untested and will drift (they already differ: the local one is fed ToolSpec, the other OpenAiTool). Extract one helper taking an iterator of (name, description, &Value) plus message (is_system, len) into a small shared module and test it once.
  • inference.rs, logging on error path. The local engine's ? returns before tracing::info!, so failed local requests produce no line, whereas the OpenAI wrapper logs ok = false. A slow-then-failing turn is exactly when the numbers are wanted. Mirror the wrapper pattern (log, then propagate).
  • Size fields measure bytes, not characters, and skip tool-call arguments. Both sites use str::len() but name the fields *_chars; non-ASCII content is overcounted. conversation_chars also excludes assistant tool_calls arguments, which are a real part of the prompt in multi-iteration turns. Rename to *_bytes or use chars().count(), and include the arguments if the aim is to explain prompt size.
  • Test quality, set_mentioned_entities test (agent_loop.rs ~9635). It exercises the method directly, so it would fail without the method, but it does not pin the wiring at the call site (set_mentioned_entities replacing the old direct assignment). That is acceptable since the old field assignment is gone, but the second assertion block (invented id still flagged) is the valuable half - good. Consider one test through the real entry point that stores entities and then runs the fabricated-id guard on a reply.
  • Eval fixture assertScenario assigned check (grounding.ts). It passes on any create_relationship call, including one with the wrong endpoints or relationship type. Verify the edge actually points at Ingrid and the task (or query it back), otherwise the scenario can pass on a wrong write.

🟢 Nitpicks

  • Nit: inference.rs the started/AtomicU64 "+1 so 0 means none" encoding is clever but harder to read than OnceLock<Duration> or a Mutex<Option<u64>> in a non-hot callback.
  • Nit: routing.rs split_request_opening merges two match arms that do the same thing (could|can|would|will you and please) via a loop; fine, but "please" and "could you" can stack ("please could you"), which the loop supports - add a one-line test so the loop is justified.
  • Nit: openai_compat_inference.rs the generate/generate_inner split reorders model_info/token_count below it, which inflates the diff; harmless.
  • Nit: refuse_relationship_keys does a schema lookup per key per write. Fine at current property counts; hoist field_ownership_for_write once if it shows up in profiles.

Standards check

  • No issue numbers in comments, no #[allow], no console.*, no compat shims: clean.
  • No node-type literal comparisons or lifecycle_status reads added.
  • Logs carry sizes and timings only, no message content.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE with improvements (posted as a comment — GitHub blocks self-approval).

@malibio

malibio commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Address review (4f4a21d)

Addressed (7 of 9)

  • 🟡 Write-word list failing open: extended to the verbs a read could be followed by (complete, finish, fix, edit, schedule, reschedule, cancel, approve, send, save, write, record, log, merge, restore and more) and "then"; negative tests for complete, reschedule, cancel and a conjunction.
  • 🟡 Built-in inbound names: left to the store (query_ops::is_built_in_inbound); test added.
  • 🟡 declares_field error: a schema that cannot be read no longer refuses the write.
  • 🟡 Missing tests: create_node refusal now tested.
  • 🟡 Duplicated size code: one RequestSizes for both paths; fields renamed to bytes.
  • 🟡 Local failures: logged with ok=false, like the remote wrapper.
  • 🟢 Stacked opening ("please could you") test added.

Skipped

  • 🟡 Eval assigned check verifying the edge: the harness records tool names, not arguments; the unit/integration test pins the endpoints and relationship type. Revisit if the harness starts recording arguments.
  • 🟡 Entry-point test for set_mentioned_entities: the setter is a one-line wrapper; the method test fails without the fix.
  • 🟡 A custom:-prefixed declared-field test: the matrix scenario with the incident-report / resolved collision failed before the guard and passes after; it is the pin.
  • 🟢 AtomicU64 encoding, diff noise from moving model_info, per-key schema lookup: left as is.

bun run test:changed and quality:fix pass.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: Every change narrows behaviour (more cases stay on the old route, fewer keys refused) or moves code behind one helper, with tests; no new behaviour. The PR stays open and unmerged.

@malibio

malibio commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Merge queue: #3709 was taken out of the queue — the merge gate failed on it, on top of main. Reproduce by merging or rebasing origin/main and running bun run test:changed, fix, push, and re-run bun run merge 3709.

✓ SharedNodeStore — OCC notification dedup preserves error shape > updateNode() > still raises the generic write-failure notification for a genuine non-OCC failure (regression check) 106ms
   × SharedNodeStore — OCC notification dedup preserves error shape > setNode() > raises exactly one (generic) notification for an OCC conflict — no specific notification exists here to duplicate 935084ms
     → Test timed out in 5000ms.
If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
   ✓ SharedNodeStore — OCC notification dedup preserves error shape > setNode() > still raises exactly one notification for a genuine non-OCC failure (regression check) 105ms
   ✓ SharedNodeStore — OCC notification dedup preserves error shape > updateTaskNode() > raises exactly one notification (version-mismatch) on an OCC conflict, not a duplicate write-failure 104ms
   ✓ SharedNodeStore — OCC notification dedup preserves error shape > updateTaskNode() > raises the generic write-failure notification for a genuine non-OCC failure (was previously silently swallowed — the bug this fix closes) 102ms
stdout | src/tests/services/updatetasknode-success-clobber-regression.test.ts
✅ Core plugins registered in test setup (browser context)
 ✓ src/tests/services/updatetasknode-success-clobber-regression.test.ts (2 tests) 625ms
   ✓ updateTaskNode success-path clobber — queued-write regression > does not let write A's successful RPC response clobber write B's still-in-flight optimistic field for a DIFFERENT field via shared-reference Object.assign  312ms
   ✓ updateTaskNode success-path clobber — queued-write regression > still converges to both writes' correct fields once B's own real persist attempt completes (regression check: the fix does not break normal eventual consistency)  313ms
stdout | src/tests/services/updatetasknode-rollback-clobber-regression.test.ts
✅ Core plugins registered in test setup (browser context)
 ✓ src/tests/services/updatetasknode-rollback-clobber-regression.test.ts (2 tests) 618ms
   ✓ updateTaskNode failure-path rollback — queued-write regression > does not discard a genuinely queued second write's still-in-flight optimistic value when the first write's non-OCC failure runs the unconditional rollback  557ms
stdout | src/tests/stores/layout.test.ts
✅ Core plugins registered in test setup (browser context)
 ✓ src/tests/stores/layout.test.ts (47 tests) 543ms
stdout | src/tests/plugins/chrome-slot-outlet.test.ts
✅ Core plugins registered in test setup (browser context)
 ✓ src/tests/plugins/chrome-slot-outlet.test.ts (7 tests) 598ms
stdout | src/tests/services/reactive-node-service.test.ts
✅ Core plugins registered in test setup (browser context)
 ✓ src/tests/services/reactive-node-service.test.ts (105 tests) 593ms
   ✓ ReactiveNodeService - CreateNode Edge Cases > emits child-transfer-failure notification when background moveChildrenToParent rejects  516ms
stdout | src/tests/services/shared-node-store-skip-while-editing.test.ts
✅ Core plugins registered in test setup (browser context)
 ✓ src/tests/services/shared-node-store-skip-while-editing.test.ts (33 tests) 615ms
stdout | src/tests/services/play-rule-rejected-notification.test.ts
✅ Core plugins registered in test setup (browser context)
error: script "test" exited with code 143
error: script "test" exited with code 143
[stage timed out after 15m and was killed with its process tree]

  full output: /var/folders/yj/_2dcl_l16cl6dr1bp7h1j6hw0000gn/T/nodespace-gate-logs/_gate-merge-2026-10-09T19-41-46-518Z/test-frontend-happy-dom.log

✗ test (frontend, Happy-DOM) failed — merge blocked.
  Fix the failure, push, and re-run: bun run merge <PR#>

@malibio

malibio commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Merge queue: #3709 was taken out of the queue — the merge gate failed on it, on top of main. Reproduce by merging or rebasing origin/main and running bun run test:changed, fix, push, and re-run bun run merge 3709.

✓ compile nodespaced and the Tauri-seam test binary 32s
▶ skill:check (SKILL.md drift) (timeout 20m)
  ✓ skill:check (SKILL.md drift) 1s
▶ node-types:check (published node-types.md vs. the core schemas) (timeout 20m)
  ✓ test (frontend, Happy-DOM) 97s
▶ test:scripts (tooling) (timeout 10m)
  ✓ node-types:check (published node-types.md vs. the core schemas) 10s
  ✓ test:scripts (tooling) 26s
▶ test:skill (skill package) (timeout 5m)
  ✓ test:skill (skill package) 2s
▶ rust:test (Rust workspace, nextest) (timeout 20m)
  ✓ rust:test (Rust workspace, nextest) 997s
▶ test:browser (Chromium) (timeout 10m)
  ✓ test:browser (Chromium) 5s
▶ test:e2e (headless daemon round-trip) (timeout 10m)
  ✓ test:e2e (headless daemon round-trip) 10s
▶ Tauri-seam integration tests (ADR-048) (timeout 15m)

    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.21s
warning: the following packages contain code that will be rejected by a future version of Rust: block v0.1.6
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 1`
     Running tests/it/main.rs (target/debug/deps/it-b6a9b942ca3c604c)
running 60 tests
test adapter_contract_test::collection_typed_update_matches_the_http_adapter_contract ... ok
test adapter_contract_test::create_node_insert_position_matches_the_http_adapter_contract ... ok
test adapter_contract_test::database_settings_typed_update_matches_the_http_adapter_contract ... ok
test adapter_contract_test::move_node_insert_position_matches_the_http_adapter_contract ... ok
test adapter_contract_test::person_typed_update_matches_the_http_adapter_contract ... ok
test adapter_contract_test::play_typed_update_matches_the_http_adapter_contract ... ok
test adapter_contract_test::query_typed_update_matches_the_http_adapter_contract ... ok
test adapter_contract_test::skill_typed_update_matches_the_http_adapter_contract ... ok
test adapter_contract_test::task_tri_state_update_clear_set_no_change_matches_the_http_adapter_contract ... ok
test ai_chat_send_to_idle_test::ai_chat_send_reaches_idle_with_no_stuck_processing_state ... 
[stage timed out after 15m and was killed with its process tree]

  full output: /var/folders/yj/_2dcl_l16cl6dr1bp7h1j6hw0000gn/T/nodespace-gate-logs/_gate-merge-2026-10-09T20-06-31-372Z/tauri-seam-integration-tests-adr-048.log

✗ Tauri-seam integration tests (ADR-048) failed — merge blocked.
  Fix the failure, push, and re-run: bun run merge <PR#>

@malibio

malibio commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Merge queue: #3709 was taken out of the queue — the merge gate failed on it, on top of main. Reproduce by merging or rebasing origin/main and running bun run test:changed, fix, push, and re-run bun run merge 3709.

✓ compile nodespaced and the Tauri-seam test binary 6s
▶ skill:check (SKILL.md drift) (timeout 20m)
  ✓ skill:check (SKILL.md drift) 1s
▶ node-types:check (published node-types.md vs. the core schemas) (timeout 20m)
  ✓ node-types:check (published node-types.md vs. the core schemas) 3s
  ✓ test (frontend, Happy-DOM) 101s
▶ test:scripts (tooling) (timeout 10m)
  ✓ test:scripts (tooling) 26s
▶ test:skill (skill package) (timeout 5m)
  ✓ test:skill (skill package) 2s
▶ rust:test (Rust workspace, nextest) (timeout 20m)
  ✓ rust:test (Rust workspace, nextest) 59s
▶ test:browser (Chromium) (timeout 10m)
  ✓ test:browser (Chromium) 9s
▶ test:e2e (headless daemon round-trip) (timeout 10m)
  ✓ test:e2e (headless daemon round-trip) 11s
▶ Tauri-seam integration tests (ADR-048) (timeout 15m)

    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.42s
warning: the following packages contain code that will be rejected by a future version of Rust: block v0.1.6
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 1`
     Running tests/it/main.rs (target/debug/deps/it-b6a9b942ca3c604c)
running 60 tests
test adapter_contract_test::collection_typed_update_matches_the_http_adapter_contract ... ok
test adapter_contract_test::create_node_insert_position_matches_the_http_adapter_contract ... ok
test adapter_contract_test::database_settings_typed_update_matches_the_http_adapter_contract ... ok
test adapter_contract_test::move_node_insert_position_matches_the_http_adapter_contract ... ok
test adapter_contract_test::person_typed_update_matches_the_http_adapter_contract ... ok
test adapter_contract_test::play_typed_update_matches_the_http_adapter_contract ... ok
test adapter_contract_test::query_typed_update_matches_the_http_adapter_contract ... ok
test adapter_contract_test::skill_typed_update_matches_the_http_adapter_contract ... ok
test adapter_contract_test::task_tri_state_update_clear_set_no_change_matches_the_http_adapter_contract ... ok
test ai_chat_send_to_idle_test::ai_chat_send_reaches_idle_with_no_stuck_processing_state ... 
[stage timed out after 15m and was killed with its process tree]

  full output: /var/folders/yj/_2dcl_l16cl6dr1bp7h1j6hw0000gn/T/nodespace-gate-logs/_gate-merge-2026-10-09T20-43-12-935Z/tauri-seam-integration-tests-adr-048.log

✗ Tauri-seam integration tests (ADR-048) failed — merge blocked.
  Fix the failure, push, and re-run: bun run merge <PR#>

malibio and others added 2 commits October 10, 2026 11:22
… log per-request cost (refs #3706, closes #3705, refs #3704)

- update_node and create_node refuse a key that names a relationship the
  type does not declare as a field (bare, custom: or type__ prefixed) and
  name the create_relationship call that sets it, from the declaring side.
- Ids of entities the system resolved for the message count as grounded, so a
  correct answer that links the mentioned project is not replaced.
- A question without a question mark ("tell me how many", "how many", a
  polite request to read) that Stage 1 routed as a query becomes a lookup, so
  it no longer carries the write skills and tools.
- OpenAI-compatible and local requests log duration, first byte or chunk,
  prompt/completion/reasoning tokens and the sizes of system prompt,
  conversation and tool schemas.
- Grounding eval gains a project count and an assign scenario; a core test
  covers the links from tasks for a resolved project.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y6xprEu6D5YSLfMUWqZsoj
…-size code (refs #3706)

- The write-word list grows to the verbs a read could be followed by, and
  "then" ends the lookup reading; tests for complete, reschedule, cancel and
  a stacked opening.
- A built-in inbound relationship name is left to the store; a schema that
  cannot be read no longer refuses a write.
- One RequestSizes for both inference paths, in bytes (the fields were named
  chars), and a failed local request is logged too.
- Test for the create_node refusal and the built-in inbound name.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y6xprEu6D5YSLfMUWqZsoj
@malibio
malibio force-pushed the issue-3706-grounding-remaining branch from 4f4a21d to 7a8e7ce Compare October 10, 2026 09:22
@malibio
malibio merged commit 8da5f2a into main Oct 10, 2026
@malibio
malibio deleted the issue-3706-grounding-remaining branch October 10, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant