Skip to content

Ground ids the application wrote into a chat's opening message - #4269

Merged
mstomar125 merged 1 commit into
mainfrom
fix/4245-opening-ids-grounded
Nov 13, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
fix/4245-opening-ids-grounded

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Refs #4245

Root cause

The fabricated-id guard (agent_loop.rs, final-reply path) replaces a reply with the confirmation request when it names a nodespace:// id that is not in session.grounded_node_uris. That set is fed by tool results, system records, resolved entities, and the pinned-nodes record (which grounds the chat's own node). It is not fed by the message a bound chat is opened with (bound_chat.rs, an Assistant-role message the application writes). That opening links the node itself and, for a type, the type it extends and the types that declare inherited fields. Only the chat's own node is covered, via the pinned-nodes record. A parent/owner type named by a hyphenated id (for example nodespace://software-project) is not grounded and the plain-type-name unlink repair does not cover it, so a correct reply linking it became "I'd like to help with that. Could you confirm...".

How app-written is told apart from model-written

ChatMessage carries no provenance, so the history alone cannot say. The daemon reads the stored chat, where order does: a model reply answers a user message, so no model message can precede the user's first. The assistant messages before the user's first message are the application's opening (ADR-090 section 3; prior_turns_from_history already uses the same rule to leave it out). application_opening_text takes exactly those messages and nothing later; the daemon passes the text to the session via ground_session_opening_message, which grounds only the ids in it. with_history is unchanged: an Assistant message in a starting history is still not grounded by being there.

Fix

  • AgentSession::ground_app_written_text + LocalAgentService::ground_session_opening_message (agent).
  • application_opening_text and the call in the ai-chat turn path (daemon).

Tests (all deterministic, stub/mock engines)

  • agent a_reply_linking_the_id_the_opening_message_linked_is_kept
  • agent a_fabricated_id_is_still_refused_after_the_opening_is_grounded (invented id in the same reply as a real opening link is still refused)
  • agent an_id_the_model_wrote_earlier_is_not_grounded_by_the_history (guard regression)
  • daemon a_type_chats_reply_may_link_the_parent_its_opening_message_linked (real bound type chat through maybe_handle_ai_chat_node)
  • daemon only_messages_before_the_users_first_are_the_applications_opening

Mutation results (each reverted afterwards)

  • ground_app_written_text made a no-op: the "kept" test fails (reply replaced); the daemon e2e also fails (reply is the canned confirmation).
  • Daemon call site disabled (if false &&): the e2e test fails with the canned confirmation.
  • with_history also grounds Assistant messages: an_id_the_model_wrote_earlier... fails.
  • ground_app_written_text also grounds an invented id: the fabricated-id test fails.
  • application_opening_text without the take_while (all assistant messages): the unit test fails.

Honest limits

  • The failing tests cannot fail "on main" as written for the agent-level API, since the new method does not exist there; the no-op mutation is the equivalent, and the daemon e2e test goes through existing entry points and fails without the call site.
  • Finding on Needs a live model: verify typed-question routing on the local agent (prompt dump, eval scenarios) #4245: the live harness (tests/it/live_typed_question_routing.rs) builds its session without the pinned-nodes record, so the type's own link nodespace://software-project is ungrounded there but IS grounded in the app. The live Q1 canned reply is therefore partly a harness artefact; in the app the real gap is links to other ids the opening wrote (parent/owner types). This PR fixes that gap; the harness mismatch is not changed here.
  • The rule assumes the app is the only writer before the user's first message. No live-model run was done; Needs a live model: verify typed-question routing on the local agent (prompt dump, eval scenarios) #4245 still needs its live pass.
  • cargo test -p nodespace-agent --lib once failed a_held_update_nodes_schema_decision_is_the_nodes_type_and_enforced in the full run; it passes alone on this branch and on main (looks order/flake dependent, untouched code). Daemon lib: 496 passed. fmt and clippy -D warnings clean. The pre-push hook is lint-only.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Correction to the limits note: the full-run failure of a_held_update_nodes_schema_decision_is_the_nodes_type_and_enforced reproduces identically on origin/main (1048 passed, 1 failed; passes when run alone), so it is pre-existing and unrelated to this PR.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Merge queue: #4269 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 4269.

cargo:rerun-if-env-changed=CFLAGS_aarch64_apple_darwin
  CFLAGS_aarch64_apple_darwin = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64-apple-darwin
  CFLAGS_aarch64-apple-darwin = None
  cargo:warning=sccache: error: Server startup failed: File exists (os error 17)
  cargo:warning=Run with SCCACHE_LOG=debug SCCACHE_NO_DAEMON=1 to get more information
  exit status: 2
  cargo:warning=ToolExecError: command did not execute successfully (status code exit status: 2): env -u IPHONEOS_DEPLOYMENT_TARGET LC_ALL="C" "/Users/mayanktomar/nodespace/core/.tools/bin/sccache" "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=arm64-apple-macosx" "-mmacosx-version-min=27.2" "-I" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/include" "-I" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/pregenerated" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-Wall" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-gfull" "-DNDEBUG" "-o" "/Users/mayanktomar/nodespace/core/.claude/worktrees/_gate/target/debug/build/ring-02464c93aa49b344/out/a0330e891e733f4e-ecp_nistz.o" "-c" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/crypto/fipsmodule/ec/ecp_nistz.c"
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  --- stderr
  error occurred in cc-rs: command did not execute successfully (status code exit status: 2): env -u IPHONEOS_DEPLOYMENT_TARGET LC_ALL="C" "/Users/mayanktomar/nodespace/core/.tools/bin/sccache" "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=arm64-apple-macosx" "-mmacosx-version-min=27.2" "-I" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/include" "-I" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/pregenerated" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-Wall" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-gfull" "-DNDEBUG" "-o" "/Users/mayanktomar/nodespace/core/.claude/worktrees/_gate/target/debug/build/ring-02464c93aa49b344/out/a0330e891e733f4e-ecp_nistz.o" "-c" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/crypto/fipsmodule/ec/ecp_nistz.c"
error: script "shape:check" exited with code 101
[stage exited with code 101]

  full output: /var/folders/3w/y9kj522n1_j9wqmt6vl_sb6r0000gp/T/nodespace-gate-logs/_gate-merge-2026-11-13T07-46-02-300Z/shape-check-built-in-shape-snapshot-and-change-log.log

✗ shape:check (built-in shape snapshot and change log) failed — merge blocked.
  Fix the failure, push, and re-run: bun run merge <PR#>

The fabricated-id guard grounds ids from tool results and system records
only, so a reply linking a type the bound chat's own opening message
linked (for example the type a custom type extends, named by its
hyphenated id) was replaced by the confirmation request.

The daemon now passes the application-written opening (the assistant
messages before the user's first) to the session, which grounds the ids
in it. Assistant messages after the user's first stay ungrounded.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the fix/4245-opening-ids-grounded branch from 3945549 to a61f4e5 Compare November 13, 2026 08:04
@mstomar125
mstomar125 merged commit 28171a1 into main Nov 13, 2026
@mstomar125
mstomar125 deleted the fix/4245-opening-ids-grounded branch November 13, 2026 08:05
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