Skip to content

fix(runtime): preserve progress and interrupted task context - #1422

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
gouhongshen:codex/fix-progress-and-interrupted-history
Dec 1, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
gouhongshen:codex/fix-progress-and-interrupted-history

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Capability assessment: Updated: preserves assistant progress content and bounded interrupted-input continuation through the canonical Context owner; recovery binds its captured scope to a measured index outside locked admission. No new provider, execution profile, endpoint or tool authority. See docs/design/runtime-lifecycle.md and docs/design/data-and-storage.md.

🤖 Bot | Codex | Codex

Summary

Long tasks lose context when tool-round assembly replaces emitted assistant text with null, or when an executor stops before committing an accepted request to canonical Context. Preserve the text in its existing assistant/tool envelope and restore eligible immutable opening inputs through the existing Context owner.

Interrupted-input recovery now has a bounded forward path. Select recent eligible inputs by owner, Session, unfinished turn and authority epochs before applying the row and byte limits. Recover at most 200 inputs, 32 MiB of stored openings and 256 KiB of serialized input. When accepted input exceeds that window, retain its immutable opening and send an explicit incomplete-history/unknown-effects observation; the next Run can still commit and the Session can continue. This does not recreate uncommitted tool calls or prove that external effects did not occur.

The locked Session admission read retains its original occupancy/capture work. After the opening transaction commits, recovery planning uses the captured Context scope as a literal indexed lookup. Each fresh root adds one body-free metadata query; its recovery base/index reads are bounded independently of retired history. A nonempty plan reserves capacity using exact stored/input byte costs captured at admission, then loads and validates selected complete openings in one query. Resumed executable custody retains its separate existing path. There is no per-opening query or new recovery cursor.

Related issue

Closes #1420.
Related continuity work: #1296 and #1304; this PR does not resolve their other concerns.
MOI prompt/long-command guidance: https://github.com/matrixorigin/matrixflow/pull/22938 (matrixorigin/matrixflow#22935).

Change type

  • Feature
  • Bug fix
  • Documentation
  • Refactor or performance improvement
  • Test
  • Build, CI, or maintenance

User and compatibility impact

The next inference retains assistant text already emitted before tools and eligible original requests after an interrupted Run. When recovery is incomplete, the model receives that fact and must explain missing context and obtain the needed details before acting. Existing committed history remains authoritative. This is bounded input recovery, not resumption of an expired executor or a guarantee against repeated model wording.

Database compatibility change: Astra advances the existing fresh-schema contract to 2026-12-01-v135. agent_runs adds context_recovery_scope, context_recovery_bytes, context_input_bytes and the owner/Session/scope/admission-order index. Earlier schemas are rejected by the existing startup contract. There is no implicit migration or backfill; deploying this build against an existing database requires an explicit fresh-schema cutover. It must not be treated as an in-place, schema-compatible binary update.

MOI schema and Offset are unchanged. No public HTTP API, SDK wire model or configuration changes. Assistant text remains subject to the existing serialized Context budget.

Architecture and complexity delta

  • Canonical owners extended: shared headless assistant/tool assembly, immutable Run admission metadata and DatabaseSessionContextCoordinator. The temporary admission recovery hint/join is removed.
  • Existing paths inspected: root opening/terminal transactions, resumed execution, authority epochs, canonical WAL/delta assembly, weighted admission, cold opening identity validation and existing SQL-budget tests.
  • Removed historical recovery discovery from the locked admission statement. Recovery planning uses the measured owner/Session/scope index with literal bounds; full hash/Context identity checks remain before reuse.
  • No additional table, admission write, execution grant, context store, recovery cursor, process cache or saved-tool replay path is introduced. Existing terminal Context commit advances the turn and retires the recovery window.

Verification

  • Regression proof: the new real-DB count-cap journey fails on the original implementation with 503 uncommitted Run inputs exceed the history admission limit; the same journey passes after the fix.
  • Runtime/database verification (feature branch based on main c270d7d57):
    • ASTRA_TEST_DB_IT=1 RUST_MIN_STACK=16777216 cargo test -p astra-runtime --lib interrupted_history_tests:: -- --ignored --test-threads=1 --nocapture: 7 passed on real local MatrixOne 4.2.9 in an isolated fresh v135 database (20.14s).
    • Includes no committed head/warm history, loss after successful tool rounds, count/byte overflow with subsequent same-Session success, obsolete epochs, 5,000 retired openings and capacity rejection before decoding a malformed cold body.
    • Healthy recovery lookup at both 0 and 5,000 retired openings: 2 base rows and 1 index row, diagnosed from the emitted production query with EXPLAIN ANALYZE.
    • The earlier dynamic locked join read all 5,004 owner rows on the same MO 4.2.9 fixture; it is removed. The previous metadata query also scanned 5,004 index entries; the measured scope index removes that enumeration. Existing pre-PR occupancy checks retain their baseline behavior.
    • make format-check and git diff --check: passed.
    • Schema inventory duplicate/foreign-key checks: passed; schema inventory test script: 47 passed.
    • cargo clippy -p astra-services -p astra-runtime --lib --tests -- -D warnings: passed.
    • MEMORIA_SELF_HOSTED_MASTER_ACCESS=1 ASTRA_TEST_DB_IT=1 RUST_MIN_STACK=16777216 cargo test -p astra-runtime --features e2e-hooks --test chat_sql_budget ordinary_chat_and_readonly_rounds_have_bounded_total_sql -- --ignored --exact --nocapture: passed (nine HTTP scenarios, 18–20 total SQL statements, unchanged 20-statement gate, 23.71s).
  • Product boundary exercised: real Run admission, streaming/non-streaming continuation, outgoing provider messages and normal atomic terminal Context commit. No saved tools are reconstructed or replayed.
  • The schema was bootstrapped and exercised against a disposable database; no existing deployment database was migrated or cleared.
  • Full workspace/static, frozen-MOI-consumer and other online suites remain for current-head CI.

Final checklist

  • Tests cover the behavior at the owning runtime/database boundary.
  • Runtime, storage and testing contracts are updated, including the schema cutover requirement.
  • The diff contains no credentials, customer data, private URLs, generated artifacts or test logs.
  • The PR title follows Conventional Commit style.

@gouhongshen gouhongshen self-assigned this Nov 30, 2026
@mergify

mergify Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preserving assistant text in the existing tool-round envelope and serialized budget is the right ownership. The real-DB tests cover interrupted input reaching the next inference without replaying tools. The recovery lookup has two independent blockers. CI is green. I ran the exact SQL with the PR schema and synthetic data on local MatrixOne. I did not rerun the full runtime suite.

@gouhongshen
gouhongshen force-pushed the codex/fix-progress-and-interrupted-history branch from b3fcf59 to c5cc28b Compare December 1, 2026 04:17
@gouhongshen
gouhongshen requested a review from XuPeng-SH December 1, 2026 04:23

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preserving progress in the existing tool-round envelope remains well scoped. The new recovery selection gives over-limit sessions a forward path, excludes revoked epochs before selection, and reserves capacity before loading opening bodies. The remaining blocker is the actual database work in ordinary admission. Moving the lookup into the existing statement removes a round trip, but the MatrixOne execution plan still adds a history-sized scan under the Session fence. The inline finding includes a base/head comparison on local MatrixOne 4.2.9.

Comment thread crates/services/src/storage.rs Resolved
@gouhongshen
gouhongshen requested a review from XuPeng-SH December 1, 2026 05:17

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three prior findings are addressed. Oversized or obsolete inputs no longer prevent the Session from advancing, and cold opening bodies still require the weighted permit. The locked Session read is back to its existing occupancy and capture checks. On local MatrixOne 4.2.9 I ran the exact new recovery SQL with the v135 DDL. Zero, 5,000 retired, and 5,000 retired plus 5,000 unrelated Runs each read two base rows and one recovery-index row for an empty plan. The prepared statement in the cold case included only eligible earlier inputs and excluded later, revoked, or old-epoch rows. The added SELECT is per fresh root, outside the lock, with no opening body on the healthy path. Recovery remains with the canonical Context owner. The new test asserts scan work, and the docs identify the extra statement and v135 deployment boundary. The local check exercised the SQL and plans independently of the runtime CI suite.

@mergify mergify Bot added the queued label Dec 1, 2026
@mergify

mergify Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as 5499a2e at 05:48 UTC

Less than a minute in the queue, with no time running CI.

So far

  • ✅ Entered the queue Tue 1 Dec, 05:48 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged 05:48 · 5499a2e · squash
17 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = Check PR title
    • check-neutral = Check PR title
    • check-skipped = Check PR title
  • any of · required by GitHub branch protection:
    • check-success = check
    • check-neutral = check
    • check-skipped = check
  • any of · required by GitHub branch protection:
    • check-success = Test: core crates + bridge hooks
    • check-neutral = Test: core crates + bridge hooks
    • check-skipped = Test: core crates + bridge hooks
  • any of · required by GitHub branch protection:
    • check-success = Test: astra-runtime
    • check-neutral = Test: astra-runtime
    • check-skipped = Test: astra-runtime
  • any of · required by GitHub branch protection:
    • check-success = Test: astra-cli (edge-fs-tools)
    • check-neutral = Test: astra-cli (edge-fs-tools)
    • check-skipped = Test: astra-cli (edge-fs-tools)
  • any of · required by GitHub branch protection:
    • check-success = Test: astra-cli (edge-git-gix)
    • check-neutral = Test: astra-cli (edge-git-gix)
    • check-skipped = Test: astra-cli (edge-git-gix)
  • any of · required by GitHub branch protection:
    • check-success = Test: astra-cli (edge-rest)
    • check-neutral = Test: astra-cli (edge-rest)
    • check-skipped = Test: astra-cli (edge-rest)
  • any of · required by GitHub branch protection:
    • check-success = Test: astra-cli (edge-shell)
    • check-neutral = Test: astra-cli (edge-shell)
    • check-skipped = Test: astra-cli (edge-shell)
  • any of · required by GitHub branch protection:
    • check-success = Test: astra-cli (non-edge)
    • check-neutral = Test: astra-cli (non-edge)
    • check-skipped = Test: astra-cli (non-edge)
  • any of · required by GitHub branch protection:
    • check-success = Test: online (core)
    • check-neutral = Test: online (core)
    • check-skipped = Test: online (core)
  • any of · required by GitHub branch protection:
    • check-success = Test: online (integration)
    • check-neutral = Test: online (integration)
    • check-skipped = Test: online (integration)
  • any of · required by GitHub branch protection:
    • check-success = Test: turn-core + services + plan
    • check-neutral = Test: turn-core + services + plan
    • check-skipped = Test: turn-core + services + plan
  • any of · required by GitHub branch protection:
    • check-skipped = web (typecheck, test, build)
    • check-neutral = web (typecheck, test, build)
    • check-success = web (typecheck, test, build)
  • any of · required by GitHub branch protection:
    • check-skipped = Astra SDK (typecheck, test+coverage, build)
    • check-neutral = Astra SDK (typecheck, test+coverage, build)
    • check-success = Astra SDK (typecheck, test+coverage, build)
  • any of · required by GitHub branch protection:
    • check-success = Test: macOS workspace coordination
    • check-neutral = Test: macOS workspace coordination
    • check-skipped = Test: macOS workspace coordination

Times in UTC · dashboard · how the merge queue works

@mergify
mergify Bot merged commit 5499a2e into matrixorigin:main Dec 1, 2026
41 checks passed
@mergify mergify Bot removed the queued label Dec 1, 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.

fix: retain assistant tool-round content and interrupted task inputs

2 participants