Skip to content

Stop the ADR-048 daemon fixture spawning a nodespaced that isn't a build of this checkout (closes #2224) - #2258

Merged
mstomar125 merged 1 commit into
mainfrom
issue-2224-ai-chat-idle-no-reply
Aug 24, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-2224-ai-chat-idle-no-reply

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Closes #2224.

What was actually wrong

Not the daemon's turn-completion path. The runs that failed spawned a 2026-07-24 nodespaced, not a build of main.

nodespace-app-test-support::resolve_daemon_binary() resolved NODESPACED_TEST_BIN, else the hand-staged sidecar at src-tauri/binaries/nodespaced-<triple>. Both are git-ignored artifacts nothing keeps in sync with the checkout, and cargo's freshness check is mtime-based, so build outputs copied in from another checkout (the standard shortcut for a fresh worktree, which has no Rust build cache) date newer than the sources and register as up to date.

An out-of-date daemon still speaks the current gRPC surface, so every RPC in the suite succeeds and only its behaviour differs. Here that behaviour was the pre-#2168 one: a turn whose inference call fails resets status to idle and appends nothing. #2168 (39d4f08a, 2026-08-19) is what replaced that with a visible assistant message — so any daemon built before that date produces exactly status="idle", assistant_count=0, and the test burns its full 300s deadline before saying so.

Evidence

Byte-identical binaries, none of them a current build (a real debug nodespaced is ~99 MB today):

26,972,864  24 Jul 11:43  core/target/debug/nodespaced                              md5 379741d5…
26,972,864  24 Jul 11:43  core/…/src-tauri/binaries/nodespaced-aarch64-apple-darwin md5 379741d5…
26,972,864  21 Aug 13:34  core-worktrees/issue-2190/target/debug/nodespaced         md5 379741d5…
98,952,648  24 Aug 08:51  this worktree/target/debug/nodespaced                     md5 93706f64…

Pointing the test at that July binary reproduces the report verbatim — same signature, same duration:

ai-chat turn did not reach idle-with-new-reply within 300s; last status="idle", assistant_count=0
test result: FAILED. finished in 309.56s

with the daemon's own log explaining it one second into the turn:

…ded: Prompt uses 6032 tokens but context window is 4096
INFO nodespace_daemon::…::local_agent_service: ai-chat turn complete

Current main passes, repeatedly, with a freshly built daemon: isolated run 39.65s ok; the gate's own step 5 (cargo test -p nodespace-app -- --test-threads=1, NODESPACED_TEST_BIN set) 30.79s ok with the whole suite green; and again after this change, 22.88s ok, suite green.

The change

  • Prefer target/debug/nodespaced over the sidecar. It is the one artifact a developer's own cargo build --bin nodespaced refreshes; the sidecar is staged only by dev:tauri:sidecars and can be arbitrarily old.
  • Refuse to spawn a daemon older than the sources compiled into it — the .rs files under packages/{daemon,agent,core,nlp-engine,nodespace-types}/src. Fails in 0.01s naming both files and how to rebuild, instead of surfacing minutes later as a behavioural failure attributed to whatever is being pushed. Unknowable inputs (no daemon sources, unstat-able binary) stay silent — this catches one specific mismatch, it is not a second way for the fixture to refuse to start.
  • Forward RUST_LOG to the spawned daemon (still defaulting to warn). The daemon's info! breadcrumbs were filtered out before reaching the drain threads, which is why the ContextOverflow line above was invisible from the test side.
  • Dump the polled node in the ai-chat timeout panic, so the failure shows what the chat node actually held rather than only two derived counters.

tests/daemon_binary_freshness_test.rs covers the check: stale rejected with an actionable message, fresh accepted, the newest crate deciding (a daemon rebuilt after a packages/daemon edit is still stale once packages/agent moves on), and unanswerable comparisons staying quiet. It runs in the gate's own cargo test -p nodespace-app step.

Out-of-scope drive-by

packages/agent/tests/live_resolve_query_decomposition_shapes.rs failed cargo clippy --all-targets -- -D warnings (collapsible_match) on main, blocking the mandatory quality:fix. Collapsed exactly as clippy directs — behaviour-preserving, test-only. Worth noting that rust:lint is not part of the pre-push gate, which is how it landed.

What was ruled out

  • The 08-21→08-23 packages/agent merges. Fresh main passes; reproducing the failure requires the July binary.
  • agent_loop.rs's completion paths. On main every run_turn return carries non-empty text (including the no-usable-final-text fallback), so the Ok arm always appends; the Err arm appends the failure message. The only remaining zero-append idle paths are cancellation (deliberate, no message by design) and a failed append_assistant_message — neither reachable here.
  • A wire-shape mismatch silently dropping messages. nodespace_core::models::AiChatMessage and nodespace_types::ai_chat::AiChatMessage are field-for-field identical, and the node dump now in the panic confirms the node genuinely held no assistant message.
  • Machine load. The July binary fails on an idle machine; the current one passes under the full serialized suite.

No production code changed.

🤖 Generated with Claude Code

…ild of this checkout (closes #2224)

`SpawnedDaemon` resolved the daemon to spawn from `NODESPACED_TEST_BIN`, else
the hand-staged `src-tauri/binaries/` sidecar. Both are git-ignored artifacts
nothing keeps in sync with the source tree, and cargo's mtime-based freshness
check treats build outputs copied in from another checkout as up to date, so a
preceding `cargo build --bin nodespaced` does not guarantee the binary matches.

An out-of-date daemon still speaks the current gRPC surface, so every RPC
succeeds and only its behaviour differs — which surfaced as
`ai_chat_send_to_idle_test` burning its full 300s deadline with the chat node
back at `status: "idle"` and no assistant reply, indistinguishable from a
regression in whatever change was being pushed.

- Resolve `target/debug/nodespaced` ahead of the sidecar: it is the artifact a
  developer's own `cargo build --bin nodespaced` actually refreshes.
- Refuse to spawn a daemon older than the `.rs` sources of the crates compiled
  into it, naming both files and how to rebuild, instead of letting the
  mismatch surface minutes later as a behavioural test failure.
- Forward `RUST_LOG` to the spawned daemon so its own breadcrumbs can be raised
  above the fixture's `warn` default when diagnosing a stall.
- Include the polled node in the ai-chat timeout panic, so the message shows
  what the chat node actually held rather than only two derived counters.

Also collapses a `collapsible_match` in an agent test that failed
`cargo clippy --all-targets` on main and blocked `quality:fix`.

Co-Authored-By: Claude <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Independent verification

Not self-merging — this closes a report filed as a production regression, and the finding is that it wasn't one. That conclusion deserves a second reader before it lands.

The claim this PR rests on, and how it was established

The report's signature (status="idle", assistant_count=0 at the 300s deadline) was reproduced on demand, by changing exactly one variable: which nodespaced the fixture spawns.

daemon spawned result
fresh cargo build --bin nodespaced (98,952,648 B, md5 93706f64…) ok — 39.65s isolated; 30.79s in the gate's step 5; 22.88s again post-change; 25.81s in this PR's own pre-push gate
2026-07-24 binary (26,972,864 B, md5 379741d5…) FAILED — 309.56s, status="idle", assistant_count=0

Four green runs against a current daemon, one red against the old one, same machine, same test, same command shape. The md5s are how I know the three "different" stale paths (core/target/debug/nodespaced, the src-tauri/binaries/ sidecar, and core-worktrees/issue-2190/target/debug/nodespaced) are one binary copied around rather than three builds — sizes alone would have been suggestive, hashes are decisive.

The mechanism is confirmed from the daemon's own log rather than inferred: ContextOverflow ("Prompt uses 6032 tokens but context window is 4096") one second into the turn, immediately followed by ai-chat turn complete and nothing appended. That is the pre-#2168 path verbatim, and #2168 merged 2026-08-19 — after the binary was built.

Where I'd push back on myself

  • "You just didn't reproduce it on current main." Four passes is not proof of absence, and this test does have a flaky history. But the failing configuration is not merely a failure — it is byte-identically the same daemon in all three checkouts where the gate failed, it fails deterministically, and its failure mode is a named, dated, already-fixed behaviour. That is a positive identification, not an absence of evidence.
  • The staleness heuristic is mtime-based, so it can misfire. Worst realistic case: cargo fmt rewrites a daemon source after a build and the next direct cargo test -p nodespace-app refuses. That refusal is correct (the binary genuinely predates the source) and the fix is one command. It cannot misfire inside the gate, where cargo build --bin nodespaced runs at step 2 and nothing between it and step 5 touches .rs files — verified by this PR's own gate run passing.
  • Making the fixture panic adds a new way for the suite to fail. Deliberately scoped against that: unknown inputs (no daemon sources under root, unstat-able binary) return Ok, covered by an_unanswerable_comparison_is_not_treated_as_stale. It only fires on a comparison it can actually make.
  • cargo build does usually replace a stale binary. Tested directly rather than assumed: copying the July binary over target/debug/nodespaced and rebuilding did restore a fresh one. So the doc comment claims only what the evidence supports — cargo's freshness check is mtime-based and copied-in artifacts can register as up to date — not the stronger "cargo never replaces a hand-placed binary", which is false.

Reviewer attention worth spending

  • DAEMON_SOURCE_DIRS is a hand-maintained list of crates compiled into nodespaced. If a new crate joins that graph and is not added here, the check silently narrows. Is there a cheaper source of truth worth using instead?
  • The drive-by collapsible_match fix in packages/agent/tests/ is outside this change's lane. It is there only because it broke the mandatory quality:fix — say the word and I'll split it out.

@mstomar125
mstomar125 merged commit 1ef49eb into main Aug 24, 2026
@mstomar125
mstomar125 deleted the issue-2224-ai-chat-idle-no-reply branch August 24, 2026 07:06
@mstomar125

Copy link
Copy Markdown
Contributor Author

Independent verification (mstomar125)

Read the full diff directly, not just the investigation summary.

Root-cause claim: cross-checked against PR#2168's own regression test
(failed_inference_turn_surfaces_a_visible_error_not_silent_idle) — the
error string match against a pre-2168 daemon's status="idle"/no-reply
behavior is a solid, falsifiable link, not a guess.

daemon_binary_freshness: correct max-mtime-across-5-source-dirs logic
(is_none_or usage is right), fails open on unanswerable inputs (missing
binary/no source dirs) rather than adding a second way to block the
fixture — matches its own stated purpose. Resolution order change
(target/debug/nodespaced preferred over the hand-staged sidecar) is the
right call since it's the artifact cargo build --bin nodespaced actually
refreshes.

Test coverage: 4 cases are well-targeted — stale-rejected,
fresh-accepted, staleness-judged-by-newest-across-all-compiled-crates (the
one that actually matters, since packages/agent not packages/daemon is
where ai-chat turn-completion logic lives), and unanswerable-inputs-are-
silent. No gaps I can find.

Drive-by clippy fix (live_resolve_query_decomposition_shapes.rs):
mechanical collapsible_match — nested if let ... if cond {} collapsed to
a single match guard, behavior-identical. Confirmed by inspection.

Risk surface: zero production code touched — this is entirely
packages/desktop-app test harness + a test-only helper crate. The one
edge case worth naming (not a blocker): a developer deliberately pointing
NODESPACED_TEST_BIN at an intentionally-older daemon for compatibility
testing would now get refused. Narrow, hypothetical, and the error message
already tells you how to override it.

Given this unblocks every core push today, merging now.

APPROVE. (posted as a comment, not a formal GitHub review — same
account authored the PR, GitHub disallows self-approval via the review API)

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.

ai_chat_send_to_idle_test times out with assistant_count=0 — blocks the pre-push gate (4/5 attempts today)

1 participant