Skip to content

Hoist a nested parent_id in create_node; add held-out task-procedure scenarios (refs #3784) - #3824

Merged
malibio merged 1 commit into
mainfrom
issue-3784-summarization
Oct 15, 2026
Merged

malibio merged 1 commit into
mainfrom
issue-3784-summarization

Conversation

@malibio

@malibio malibio commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

What this lands

Refs #3784.

  • A nested parent_id in field_values is hoisted and validated in exec_create_node. A brief or checklist item written with the parent id inside field_values is placed under that parent, and a parent_id that names no node is refused as a missing node instead of creating an orphan.
  • Ten more held-out phrasings (the -b and -c variants) in scripts/eval/fixtures/tasks.ts, so the task-procedure eval is 16 scenarios, not 6, and a change can no longer be tuned to one sentence.

What this no longer carries

The summarization change that was here (removing the prefill ceiling, keeping the turn's request verbatim) is superseded: main now has the same fix from the question-task work (keep the turn's request through compaction, bound compaction on history alone). The merge with main took main's agent_loop.rs whole; this PR's net change against main is tools.rs and tasks.ts.

Measured, one rep, same 16 scenarios, same build

Model Pass Positive writes (of 10)
Gemma 4 E4B (local) 4–5/16 0
Qwen3.8-27B 7/16 1
Claude Haiku 5.5 7/16 1

A much stronger model fails the same positives. Its traces show it writes the brief into field_values under custom:* keys, which is what create_node's guidance tells it to do, instead of text children as the procedure says. That is a prompt contradiction, not a model limit, and is the next piece of work on #3784.

🤖 Generated with Claude Code

@malibio

malibio commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

Review of PR #3824 (initial)

Verdict: COMMENT (no blockers; a few things worth fixing before merge). Self-approval is blocked, so this is posted as a comment review.

Requirements (#3784)

  • The PR is "refs", not "closes", and the measurements say so: 0 of 10 positive-write scenarios pass in any configuration; the 5 passes are the negative-assertion scenarios. The issue's remaining scope (stage a procedure's reads before its writes; how a waiting-on-a-person request reaches Creating a Task) is not met, and the PR does not claim it.
  • What it does meet: removes the time-cap failures (8 to 0 scenarios at the 180 s cap), keeps the request verbatim, fixes a silent-success write (custom:parent_id).

(a) Removing the ceiling

  • Gate 1 compares history + system to context_window - MAX_RESPONSE_TOKENS (floored at SYSTEM_PROMPT_BUDGET + 1), and context_window is the engine's granted n_ctx, so the KV cache and the window are sized together; no overflow path is opened by a long unsummarized history that gate 1 does not already cover.
  • The Metal OOM was a compute-buffer failure. I cannot prove from the diff that compute-buffer size is independent of prompt length, but the measured 19K-24K prefills on matching hardware are stronger evidence than the original single 8.5K failure, and the old ceiling could not have prevented a 20K system prompt anyway. Removing it is reasonable.
  • Gap, pre-existing but now unguarded: when model_info() is unknown the fallback is TOTAL_TOKEN_BUDGET (32,000) with no MAX_RESPONSE_TOKENS reserve, so that path is looser than the known-window path. Nit-level; remote backends enforce their own limits.

(b) Pinned request

Logic reads correct: rposition of the last user message, filtered to < split_point, remove(i) from the drained prefix (indices line up because the drain starts at 0), reinsert at 0 on the empty-older early return, summary at 0 and request at 1. Removing a user message cannot orphan a tool call/result pair (those are assistant/tool messages and the split back-off is unchanged). grounded_node_uris is derived from history/records, not from session.messages at summarization time, and is untouched.

  • 🟡 agent_loop.rs (pin block, ~6427-6445): the pinned request is not counted against the budget. A very large user message (a pasted document) used to be summarized away; now it is kept whole, so the prompt can stay over the window after "summarizing", and the next decode hits ContextOverflow. Either skip the pin when the request alone is a large share of the window, or truncate it.
  • 🟡 Same block: when the pin leaves nothing to summarize it returns Ok with the prompt still over budget, silent. Same as the existing split_point == 0 case, so consistent, but worth a log::warn!-level signal if there is a logger here.
  • 🟢 The <= 4 early return is unchanged and stays a gap (4 huge tool results are never summarized); pre-existing.

(c) parent_id hoist (tools.rs ~5116-5132)

  • 🟡 A non-string nested parent_id (number, null, object) is removed and dropped silently, and the call still reports success: the same silent-success shape this change is fixing. Return InvalidArguments for a non-string value.
  • 🟡 When both the top-level and the nested parent_id are present and differ, the nested one is dropped silently. Prefer an error, or at least be deliberate; the test does not pin either.
  • 🟡 If any core or user type declares a field literally named parent_id, the hoist now steals it. I did not find one, but node-type work is the place it would appear; worth a one-line check against the seeded schemas.
  • requested_any_properties is computed after the removal, which is right: a call whose only property was the hoisted parent_id is a content-only create, not a "dropped properties" case. refuse_relationship_keys / store_undeclared_keys see props without the key, as intended. field_values.take() is not read again.
  • collection nested in field_values: do not add it speculatively (YAGNI) unless the dumps show the model doing it; if they do, it wants the same treatment and a test.
  • update_node is not changed. If the model nests parent_id in update_node.field_values it still lands as custom:parent_id; reparenting probably goes through a different tool, so confirm that is unreachable, or note it.

(d) Tests

  • a_large_system_prompt_alone_does_not_summarize_a_short_turn fails on main (an 80K-char system prompt is over the old 8,000 ceiling with 7 messages). Good. Assertion on identical messages is the right one.
  • summarization_keeps_the_request_the_turn_is_working_on fails without the pin (messages[1] would be an assistant step). Good.
  • 🟡 Not covered: the empty-older early-return branch, a pinned request with a tool-call chain in the tail, and the parent_id cases above (non-string, conflict).
  • a_parent_id_inside_field_values_is_used_as_the_parent fails on main (the property is stored and the child is unparented). Good.

(e) Standards and comments

  • No dead code, no suppression, the constant and both old tests are deleted cleanly.
  • 🟡 The long gate comment is mostly history ("used to sit", "set after one Metal OOM") rather than mechanism, which AGENTS.md asks against. The mechanism is two sentences: the gate is the window budget; summarizing cannot shrink the system prompt, and each summarization evicts the KV cache. Move the "was a fixed 8,000 ceiling" narrative to the PR/ADR.
  • 🟡 Numbers in comments: "~20K tokens" is supported by the PR body ("system prompt alone is ~20K" and 19K-24K prefills); "75 to 100 seconds" is a daemon-log observation on one machine and "in every run measured since" is not checkable from the repo. Hardware-specific timings go stale in a comment; state the mechanism (a second full prefill) and drop the seconds.
  • 🟢 Nit: the test doc comment "far over 8,000" references the deleted constant's value; "far over the old ceiling" has the same problem. Say what the test asserts: a large system prompt inside the window is not summarized.
  • 🟢 Eval fixtures (scripts/eval/fixtures/tasks.ts): ten extra phrasings, test-data only; no concerns beyond what the PR body states (scenario count and one rep each is directional, not decision-grade).

Recommendation: COMMENT

Safe to merge after the non-string/conflicting parent_id handling and the unbounded pinned-request point are addressed (or consciously accepted), and the gate comment is trimmed to mechanism. No blocker found.

@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.

Verdict: COMMENT. No blockers. Details in the review comment above: non-string/conflicting nested parent_id is dropped silently, pinned request is unbounded, gate comment should describe mechanism not history.

@malibio

malibio commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed the review (commit 172a631):

  • ✅ 🟡 Non-string nested parent_id: refused with InvalidArguments, nothing stored (was dropped silently).
  • ✅ 🟡 Conflicting parent_id (parameter and nested differ): refused. Equal values are accepted. Test covers both refusals.
  • ✅ 🟡 Unbounded pin: the request is kept only while it is at most a quarter of the window budget (total_budget / 4, measured with the engine's token count); a larger one is summarized with the rest. Test with a 16,000-char request in a 4,096-token window.
  • ✅ 🟡 Empty-older early return: tested (request is the only message older than the kept tool-call tail; nothing is summarized, nothing changes).
  • ✅ 🟡 Gate comment: now the mechanism only; history and the 75 to 100 s figure removed. Test doc nit fixed.
  • ⏭️ 🟡 A schema field named parent_id: checked, no seeded schema declares one; a user type that does would be given the parent parameter, which the tool already documents as parent_id.
  • ⏭️ 🟢 Nested collection: not seen in any prompt dump; revisit if one is.
  • ⏭️ 🟢 update_node nested parent_id: update has no parent parameter, so there is nothing to hoist to.
  • ⏭️ 🟢 Unknown-window fallback without a response reserve and the <= 4 early return: pre-existing, outside this change.

bun run test:changed passes.

Re-Review Decision

Decision: RE-REVIEW NEEDED

Rationale: the pinned request now has a size bound in the summarizer and create_node has two new refusal paths. Both are logic changes in code that runs on every multi-step turn, made in response to the review; the reviewer should confirm the bound and the refusals do what was asked.

@malibio

malibio commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review of PR #3824 (second commit, 172a631)

Verdict: COMMENT (no blockers). Self-approval is blocked, so this is a comment review.

Previous findings

  • Non-string nested parent_id: addressed. Refused with InvalidArguments at the hoist site (tools.rs ~5126), before requested_any_properties, refuse_relationship_keys and store_undeclared_keys run, so nothing is stored. Equal values and nested-only are accepted.
  • Conflicting parent_id: addressed in the same block.
  • Unbounded pinned request: addressed. token_count(...).await? has the same error type as the two earlier calls in the function; total_budget (u32) is in scope and already holds the TOTAL_TOKEN_BUDGET fallback when the window is unknown, so / 4 is right on both paths. An oversized request is simply not pinned and goes into older_messages with the rest; the empty-older early return and everything else in the function are unchanged.
  • Empty-older early return: now tested. I traced it: 5 messages, split back-off lands at 1, older is only the request, over budget (6000 vs 4001), so the branch is reached.
  • Gate comment: now mechanism only.
  • Skipped items: I agree with both. Nested collection is speculative (YAGNI) until a dump shows it; update_node has no parent parameter, so there is nothing to hoist to.

New findings

  • Improvement, tools.rs test a_nested_parent_id_that_is_not_an_id_or_disagrees_is_refused: the assertion is_err() || unwrap().is_error is too loose, and the second case does not discriminate. nodespace://a is not a node in the test store, so that call fails on the missing parent whether or not the conflict check exists. Without the change the first case would succeed (orphan create), so it is real; the second is not. Use a real created parent for the top-level value and a different id for the nested one, assert Err(ToolError::InvalidArguments { .. }) (that is what the code returns), and assert no node was created. Also add the accepted cases (equal values; nested only) which the earlier test partly covers.
  • Nit: the pin bound is measured against the budget, but the pinned request plus summary plus tail can still exceed it for a request just under total_budget / 4. Acceptable; the bound is a heuristic and the next gate re-checks.

Recommendation: COMMENT

Logic is correct; the only item worth doing before merge is tightening the refusal test so the conflict case actually tests the conflict.

@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.

Re-review verdict: COMMENT. No blockers; both logic changes verified correct. One test (conflicting parent_id) does not discriminate because its parent does not exist; tighten it. Details in the PR comment above.

@malibio

malibio commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed the re-review (df3a944):

  • ✅ Refusal test tightened: two real parent tasks so the conflict is the only fault; matches!(.., Err(ToolError::InvalidArguments { .. })) asserted explicitly; the count of text records is unchanged after the refusals; and the same id given twice is accepted.
  • ⏭️ Nit (a request just under total_budget / 4 plus the summary and tail can still pass the budget): the bound is a heuristic and the next gate re-checks, as the reviewer said.

Tests: 1020 passed in the agent crate; quality:fix clean.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: the only change since the re-review is to a test, as the reviewer asked; no production code changed, and the reviewer verified both logic changes as correct and recommended no further changes to them.

@malibio

malibio commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

Merge queue: #3824 was taken out of the queue — it conflicts with main in: packages/agent/src/local_agent/agent_loop.rs. Merge or rebase origin/main, resolve the conflicts, push, and re-run bun run merge 3824.

@malibio malibio changed the title Keep the request through summarization and stop summarizing every procedure step (refs #3784) Hoist a nested parent_id in create_node; add held-out task-procedure scenarios (refs #3784) Oct 15, 2026
@malibio
malibio force-pushed the issue-3784-summarization branch from e5a854a to 725180b Compare October 15, 2026 21:18
@malibio
malibio merged commit b178f5c into main Oct 15, 2026
@malibio
malibio deleted the issue-3784-summarization branch October 15, 2026 21:18
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