Skip to content

fix(runtime): simplify context recovery and tool observation - #1295

Merged
XuPeng-SH merged 2 commits into
mainfrom
fix/1290-context-recovery
Nov 14, 2026
Merged

XuPeng-SH merged 2 commits into
mainfrom
fix/1290-context-recovery

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Capability assessment: Unchanged: Repairs existing context recovery, cached request assembly and task observation contracts; capability profiles, permission scopes and MOI Gate requirements remain accurate.

Summary

A high provider input sample could trigger compaction after tools were selected, skip their settlement, then trigger another archive on the next iteration even after history had shrunk. Settle the current tool batch first and give preparation one recovery path: exact deduplication, optional semantic summary, then authorized durable history storage, remeasuring between steps.

  • A typed context-window rejection now reaches the existing lossless artifact owner when deduplication cannot help. Failed storage, unavailable readers, invalid authority, cancellation and deadlines preserve evidence and the selected error.
  • Keep paid usage separate from current context pressure. One transient applicability flag determines whether the previous physical measurement still applies; actual history/model changes invalidate it, and fresh physical measurements reactivate it.
  • Keep current full cacheable tool schemas and the stable system prefix through recovery. Historical summaries use evidence messages with the existing wire-only first-user preamble for strict provider ordering.
  • Share the task_output millisecond contract and admitted observation deadline. Report observation cancellation/timeout truthfully while retaining the running task.
  • Preserve concrete callback and owner-terminal causes, including untyped/Unknown stream context.
  • Remove the CLI lifetime output counter and its duplicate read gating; current pressure, per-call limits, file-size/range, redaction and evidence controls remain authoritative.

Related issue

Refs #1290. The original external-runner cleanup, browser/cross-instance database outage, child envelope and stale provider-binding incidents were not replayed; this PR does not claim those incidents closed. #1291 will be handled as a separate follow-up.

Change type

  • Bug fix
  • Refactor or performance improvement
  • Documentation
  • Test

User and compatibility impact

Long tasks can continue after useful context recovery without abandoning selected tools or repeatedly archiving an already-relieved history. Task observation respects its requested/admitted wait and distinguishes stopping observation from stopping execution. Errors retain their concrete cause and supporting context.

No configuration or persisted format migration. Current tool authority still changes immediately when the authorized contract changes.

Architecture and complexity delta

  • Canonical owners: existing preparation, tool settlement, history artifact, invocation deadline, callback projection and provider wire assembly.
  • Searched callers include runtime/CLI/tools/core constructors, canonical rewrite publications, model installation, direct/streamed overflow and provider protocol builders.
  • Removed the post-response budget backedge, lifetime aggregate output counter/scale/read gate and obsolete tests of those paths.
  • One in-memory sample-applicability fact and one invocation-local cutoff; no additional lifecycle state machine, table, poller, saved schema or ordinary-turn SQL.
  • Local estimates after a rewrite can omit opaque provider input. A subsequent typed overflow uses bounded recovery and can truthfully fail when recovery is unavailable; this rail does not guarantee physical fit or enforce a strict provider quota.

Verification

The three CLI CI failures are corrected in test fixtures: declare cancellation with ErrorKind::Cancelled, assert the typed observation timeout, and register the held-child wait before releasing its semaphore. All three affected tests pass normally and under unsuppressed ThreadSanitizer. Production behavior and the 2-second observation budget are unchanged. Hosted CI on the updated head is pending.

  • Formatting and diff checks passed.
  • Owning runtime/CLI/tools/core all-target Clippy with e2e-hooks and warnings denied passed; the final test-fixture delta was checked again.
  • 27 exact runtime regressions, 14 CLI boundary regressions and 13 schema/cache contracts passed. The runtime cases include actual assembly into OpenAI, Anthropic and Bedrock message builders, same-valued/unknown measurements, unique invocation settlement, no-reader overflow, invalid/missing permits and late cancellation.
  • Four real Server/isolated MatrixOne 4.2.8 cases passed: native HTTP Work continuation/recovery, lossless artifact retrieval across stores with owner/session checks, unchanged provider-visible system/tool prefix, exact raw accounting and no repeated settlement/archive.
  • Two public HTTP SQL checks passed: nine controlled scenarios used 17–19 statements, including one after response; ordinary/read-only/control scenarios retained their existing budgets.
  • Full core closure: 3411 passed; tools closure: 1011 passed.
  • Unsuppressed Rust ThreadSanitizer: eight runtime and eight CLI lifecycle/cancellation/delivery cases passed without race reports, using nightly-2026-10-12 and build-std.
  • A broad runtime/CLI invocation also exposed old-contract assertions and process/environment interference. Changed-contract fixtures were corrected; failing unrelated cases were individually rechecked, including inherited NO_COLOR and exact-base controls. Those initial broad invocations are recorded as failures, not clean suite passes.
  • Required independent gpt-6.1-terra/max design and final review approved the complete source and evidence. CI was not awaited. Exact wire comparisons establish request shape, not a live provider cache-hit rate.

Final checklist

  • Tests cover the owners and real caller paths, including unhappy paths.
  • Updated context and tool-boundary design contracts.
  • Checked for credentials, private data and generated files.
  • Conventional Commit title.

@mergify

mergify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

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

Deep review of b6cfc48 against merge base 71da5a7.

Findings: no material blocker found. Recommendation: approve.

Reviewed the complete 38-file change map, with implementation, tests and documentation assessed separately.

  • The design uses the existing preparation, canonical rewrite, artifact store/reader, dispatch deadline and callback owners. The removed post-response budget branch could abandon a selected batch; settlement now precedes preparation recovery. No parallel lifecycle, table or ordinary-turn SQL observer is introduced. The one transient measurement-applicability fact preserves paid usage while invalidating an obsolete pressure floor.
  • Both preparation and streamed typed context-window failures reach the authorized lossless artifact owner when exact deduplication cannot help. Reader/writer availability, canonical permits, owner/session scope, bounded retries, cancellation and original-error precedence remain intact. The two concrete context findings recorded in #1290 have regression coverage.
  • Task observation shares the millisecond contract, policy cap and admitted absolute cutoff, with settlement time reserved separately. Observation timeout/cancellation does not claim the task or parent stopped. Callback retries preserve the original request identity and recorded result rather than rerunning the command.
  • Removing executor-lifetime output accounting retires the duplicate gating path while retaining per-call bounds, full-file size checks, ranged reads, redaction and delivered evidence. Cached requests retain current full tool schemas and stable system instructions; current authority changes still apply. Historical summaries remain evidence below the instruction prefix.
  • Tests exercise the agent loop, actual observation/process lifetime and provider message builders, not just the new flags. The CI fixture corrections use typed cancellation/timeout and establish the held-child wait before releasing it, without increasing its observation budget. Documentation accurately describes bounded recovery and remaining limits.

Validation performed in this review on machine 57, using binaries rebuilt from the reviewed worktree: 27 Runtime + 17 CLI + 13 context/schema contract tests passed, with no ignored tests in those selections; diff whitespace/conflict-marker check passed. The CLI selection includes all three repaired CI failures. Current hosted checks are complete: 36 success, 4 skipped and 1 neutral, with no failures.

Previously recorded real Server/isolated MatrixOne, public HTTP SQL and unsuppressed TSan evidence was reconciled against the source manifest: 36 paths are byte-identical, and the only subsequent changes are the two inspected test-fixture files. Those database and TSan runs were not repeated in this review.

Comment closure: the PR has no existing review threads or reviewer comments. The two context defects in the #1290 follow-up comment are addressed. Original external-runner cleanup, browser/cross-instance database outage, child-envelope and stale-binding incidents were not replayed, and this PR explicitly uses Refs rather than claiming the whole issue closed. Wire-shape checks do not establish a live provider cache-hit rate or production capacity.

Review performed by the current agent under the repository review_changes guide, without subagents or source edits.

GitHub rejected the APPROVE event because the authenticated account is also the PR author. This is a COMMENT review recording the recommendation above; it is not a formal GitHub approval.

@XuPeng-SH
XuPeng-SH merged commit 2426f7d into main Nov 14, 2026
41 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/1290-context-recovery branch November 14, 2026 08:38
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