Skip to content

fix(runtime): converge history and agent observations - #1196

Closed
XuPeng-SH wants to merge 5 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/runtime-history-and-observation-convergence
Closed

XuPeng-SH wants to merge 5 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/runtime-history-and-observation-convergence

Conversation

@XuPeng-SH

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

Copy link
Copy Markdown
Collaborator

Capability assessment: Unchanged: repairs existing canonical compaction, continuation and TUI observation contracts without adding execution authority, profiles, capabilities or persisted formats.

Summary

Long tool runs could regenerate a request-only summary without shrinking canonical history. Failed or rejected attempts could also lose protected current-turn evidence in the provider projection and poison the unrelated mechanical-compaction breaker.

Admit semantic compaction only when the existing owner establishes actual post-memory pressure and a valid canonical rewrite permit. Install the same accepted candidate in canonical history and the provider request. On rejection or unavailable inference, preserve protected history. At actual final-wire overflow, reuse the canonical compactor to evict safe older turns while preserving the exact protected suffix, then rehome authority and remeasure the complete request. Reject mismatched projections or an oversized protected suffix with the existing context-window error. Network failures remain recoverable. One run-local digest suppresses another invalid/rejected attempt only while its history, model route and effective budget remain identical. Ordinary fitting rounds no longer hash the entire canonical history for a speculative permit.

First coordinator admission initializes the existing rewrite proof; initial Context commits remain Append. Accepted rewrites retain exact active authority and retire consumed controls. Handoff validates existing rewrite authority while retaining subsequent appended messages, so a successful summary can continue through the existing recovery path. Emergency Work refresh replaces the latest typed same-kind entry and removes older duplicates, so a stale continuation cannot override the refreshed full contract; unrelated authority keeps its order.

TUI tree reconciliation fences lifecycle updates by local fetch start, including same-revision rereads, newer live activity and pending controls. Independently watermark-ordered progress, lineage and runtime facts still refresh during continuous output; same-watermark child membership also refreshes. Failed queries distinguish stale server confirmation from newer observed activity. Complete snapshots stop absent provisional rows from claiming live work without inventing terminal results or matching by reusable profile names. Terminal events racing transcript reads retain one follow-up read, and unbound gaps require matching agent identity.

Related issue

Related to #1023 and #1100. This is a scoped first repair of the reported incident. Complete durable child tool timelines, wider executor scheduling/verification, and original production model-selection latency remain follow-up work. The historical session and production workload have not been replayed here.

Change type

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

User and compatibility impact

Accepted summaries survive later rounds and continuation. Summary failure preserves current human input, tool pairing and required controls. Agent activity reflects causally newer observations and details refresh after terminal/read races. No schema, SQL, migration, public API or configuration changes. Structured overflow remains possible when protected input cannot fit.

Architecture and complexity delta

  • Canonical owners extended: Memoria compaction preparation; canonical rewrite proof, WAL and handoff; existing compaction effectiveness tracker; TUI observer/agent registry/transcript view.
  • Existing consumers inspected: first/resumed Server turns, both runtime-authority placements, request/pre-turn/final-wire compaction, continuation restore, root/child transcript updates and complete/truncated tree queries.
  • Removed superseded summary_attempted bookkeeping, semantic-failure use of the global mechanical breaker, and the obsolete WAL authorization object/pending identity left without production consumers by direct-proof handoff. Proof completion no longer performs redundant durable sanitization. Added a typed failure at the existing summary owner while retaining its Option wrapper for unchanged consumers. One admission callback gates inference after actual budget calculation, without another memory retrieval.
  • Added only one ephemeral rejected-input digest and one successful-fetch timestamp. No parallel lifecycle, persistent summary cache, extra SQL, table, timer or background worker.
  • Complete diff against merge base 7ca2d82f9: production +656/−233 (net +423), test-module code +1,593/−132 (net +1,461), docs +51/−10 (net +41) (approximate inline-test ownership counts). Removed the obsolete eight-summary baseline test, which reconstructed a retired call chain and asserted an unwanted behavior. Added focused regressions for safe old-prefix eviction, wholly protected overflow, exact projection, unavailable/invalid/no-proof summary routes, continuous live progress, stale watermark, same-watermark child membership and pending control.

Verification

  • Terminal-control fixture now models a fresh successful fetch after the local Pause intent; all attachment/owner/request/target/terminal assertions are retained. No production guard was weakened.

  • cargo test -p astra-cli --lib --no-default-features -- tui::event_loop::tests::agent_: 10 passed, 0 failed, 0 ignored.

  • cargo clippy -p astra-cli --all-targets -- -D warnings: passed, warnings denied.

  • make format-check and git diff --check: passed on final source.

  • cargo clippy -p astra-runtime -p astra-cli -p astra-turn-core --all-targets -- -D warnings: passed, warnings denied.

  • cargo test -p astra-runtime --lib --features e2e-hooks -- request_compaction_ request_summary_acceptance pre_turn_summary_continuity turn::canonical_commit::tests bridge_compaction server_loop_host::tests::handoff_ server_loop_host::tests::execution_handoff final_wire_budget required_authority_replacement active_work_attempt_continuation active_work_attempt_contract artifact_recovery_guidance --skip execution_handoff_adoption_preserves_checkpoint --nocapture: 30 passed, 0 failed, 0 ignored. The database-backed adoption test is explicitly excluded from the offline scope.

  • cargo test -p astra-turn-core --lib -- cloud::summary::tests --nocapture: 14 passed, 0 failed, 0 ignored (reused: summary implementation and dependencies are unchanged by this correction).

  • cargo test -p astra-runtime --features e2e-hooks --test compaction_owner --test compaction_survival -- --nocapture: 4 + 6 passed, 0 failed, 0 ignored (run after the prefix-eviction correction; reused for the later Work replacement helper change, which does not affect these consumers).

  • Reused unchanged V3 production validation (runtime30, TUI265, public10 and shared-summary14) remains applicable; this last change only corrects the event-loop fixture.

  • TUI: cargo test -p astra-cli --lib --no-default-features -- chat_widget::tests agent_transcript_view::tests server_agent_observer::tests in_flight_agents_view::tests: 265 passed, 0 failed, 0 ignored.

  • Public entrypoints: actual Server execute_turn with deterministic local provider transport, canonical continuation/recovery, TUI live-event and observer callbacks. No live model was used; these tests establish code behavior rather than provider semantic quality or production latency.

  • Unhappy paths: missing/stale authority; changed source/model/budget; malformed, unavailable and cancelled summaries; non-reducing candidates; both authority placements; overbudget protected final wire; modified/shortened authorized prefix; secret redaction; late responses, same-revision refresh, pending/rejected controls, independent durable labels/progress, failed queries, terminal/read races and duplicate Work authority in both provider placements.

  • Race validation: changed production state uses safe Rust with existing exclusive mutable ownership and observer Mutex; no new unsafe/FFI/atomic/synchronization code, so a memory data-race detector is not applicable to this delta. Controlled oneshot response ordering exercises the relevant logical races without sleeps. Normal unit tests are not represented as an instrumented race run.

  • Database: no SQL/schema/transaction changes. WAL authorization/recovery exercised in process; no fresh MatrixOne or production incident replay.

  • Separate gpt-6.1-terra / max V4 design and final overall review: ACCEPT, no unresolved material blocker on complete diff SHA-256 3247736d2b3ffaed19d2cd80adff5c8ce3727b97e99fc03350ab98436e2d7c38. V3 whole-PR production review and unchanged checks were reused; this correction adds one fixture line. Full workspace offline/contract gates were not rerun after this correction.

  • Prior-head shared CLI CI was 5,088/5,089 because this terminal fixture retained the old fetch timestamp; the targeted consumer matrix now passes. New CI will run on the pushed revision; pending checks are not reported as passing.

Final checklist

  • Tests updated at the owning boundaries.
  • Context and observability design contracts updated.
  • Diff checked for credentials, private URLs, generated files and sensitive inputs.
  • Conventional Commit title.

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

Approve: no blocking findings on ed6d21c, reviewing the complete 17-file diff against 7ca2d82.

The design extends the existing owners:

  • Request-summary installation stays bound to the admitted rewrite proof, exact canonical/provider projection, real human anchor, active authority and tool pairing. Invalid, unavailable, cancelled and non-reducing candidates preserve the protected source. First-turn Context commits remain Append; recovered handoffs can retain subsequent appended history without granting new execution authority.
  • TUI lifecycle reconciliation uses the existing Run identity/source/confidence model plus the local fetch-start boundary. Progress, runtime facts and child membership retain their independent durable watermark ordering. Complete-tree absence degrades confidence rather than fabricating a terminal result; terminal/read races get one bounded follow-up read.
  • Superseded WAL authorization bookkeeping is removed. There are no added SQL queries, schemas, polling timers, background workers or shared synchronization primitives. The rejected-summary fingerprint is computed at actual summary dispatch, rather than on ordinary fitting requests.

Independent verification on this exact head: 330 tests passed (14 shared-summary, 275 TUI, 30 runtime, 10 public compaction integration, and 1 real MatrixOne cross-owner checkpoint/adoption journey). The database journey used its own UUID catalog and removed it afterward. Also passed: make format-check, git diff --check, and Clippy --all-targets with warnings denied for astra-runtime, astra-cli and astra-turn-core.

There were no existing PR comments or review threads requiring resolution at review time. This validates the implementation and covered failure paths; it does not claim a replay of the production incident, live-model semantic fidelity, or measured production throughput.

GitHub rejected the APPROVE submission because the connected account is the PR author (422: cannot approve your own pull request). This COMMENT records the code-review verdict and evidence; it is not a GitHub approval.

@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is closed, so it cannot be queued. Reopen it to get the box back.

@XuPeng-SH XuPeng-SH closed this Nov 26, 2026
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