Repository navigation
fix(sessions): let agents archive their session after completing a turn - #114522
Conversation
fc78129 to
9e1eb14
Compare
|
Codex review: needs maintainer review before merge. Reviewed July 27, 2026, 7:32 AM ET / 11:32 UTC. ClawSweeper reviewWhat this changesThe PR lets an agent schedule archival of its own non-main session until its active turn and competing session work complete, using identity-checked Gateway patches to avoid archiving a reset replacement. Merge readinessKeep this PR open for the protected session-lifecycle review. The branch has credible real-Gateway proof and focused regression coverage for deferred self-archive, but it changes delayed session mutation and public Gateway patch semantics, so the lifecycle owner should confirm the final rebased behavior before merge. Priority: P2 Review scores
Verification
How this fits togetherThe sessions tool runs inside an agent turn and asks the Gateway to change persisted session metadata. This change defers a self-requested archive until lifecycle admissions release, then sends a compare-and-swap patch so reset or replacement sessions remain protected. flowchart TD
A[Agent session turn] --> B[Sessions tool]
B --> C{Self-archive of non-main session?}
C -- No --> D[Normal Gateway session patch]
C -- Yes --> E[Wait for admitted session work]
E --> F[Identity-checked Gateway patch]
F --> G[Archived session state]
D --> G
Decision needed
Why: This is a protected session-state change whose safety depends on intended lifecycle policy rather than a mechanically provable local patch defect. Before merge
Agent review detailsSecurityNone. PR surfaceSource +196, Tests +777, Other +8. Total +981 across 9 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land a rebased version only after the session-lifecycle owner confirms the delayed archive state machine and the additive Gateway protocol fields preserve existing ordinary session patches. Do we have a high-confidence way to reproduce the issue? Yes. The PR supplies a concrete real-Gateway path: an agent-selected sessions tool call attempts to archive its own active non-main session, which previously returned the active-run error; the after-fix run reports scheduled and then archived state. Is this the best way to solve the issue? Yes, subject to protected lifecycle review. Deferring only non-main self-archive and using an identity-checked Gateway mutation is narrower and safer than weakening the existing active-run protection for all archive requests. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a62abee4271a. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
9e1eb14 to
bb3e1b4
Compare
|
Merged via squash.
|
What Problem This Solves
Fixes an issue where users asking an agent to archive its current non-main session receive
Cannot archive a session with an active runbecause the model-selected archive tool call runs inside that same active agent turn.Why This Change Was Made
The session-lifecycle maintainer explicitly requested this product behavior: special-case agent self-archive, finish the current response, and then archive the session. Schedule only a non-main self-archive after the initiating admission and any competing work have completed; guard immediate metadata and deferred archival with lifecycle-locked session identity and revision; retry genuinely transient Gateway failures with shutdown-safe backoff; and cancel requests if a session is reset. Preserve upstream plugin-ownership authorization, main-session protection, ordinary active-run validation, and generated native Gateway protocol compatibility.
User Impact
Users can ask an agent to archive its own session. The agent completes its final response and transcript, and the session subsequently appears under Archived without accidentally archiving a reset replacement.
Evidence
sessionstool call, and persistedsessions.list: the baseline produced the active-run error and leftarchived: false.sessionstool call,status: scheduled, followed byarchived: true,hasActiveRun: false, andstatus: done.pnpm test packages/gateway-protocol/src/index.test.ts src/agents/tools/sessions-tool.test.ts src/agents/tools/sessions-tool.self-archive.test.ts src/sessions/session-lifecycle-admission.test.ts src/gateway/server.sessions.patch-expected-identity.test.ts src/gateway/server.sessions.delete-lifecycle.test.ts src/gateway/server.sessions.reset-cleanup.test.ts src/gateway/server.sessions.plugin-ownership.test.ts.pnpm check:changed, including formatting, production and test type checks, lint, protocol and plugin compatibility, schema, database-first, and runtime import-cycle guards..agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --stream-engine-output: clean; no actionable findings.mainbase:apps/.i18n/native-source.jsoncontains 5,317 source entries while bothapps/.i18n/native/zh-CN.jsonandapps/.i18n/native/zh-TW.jsoncontain only 5,290. These existing localization artifacts are outside this session-lifecycle change; the canonical session and generated-protocol checks pass.