fix(agents): guard session prompt ownership#85955
Conversation
|
Codex review: needs maintainer review before merge. Reviewed May 25, 2026, 5:20 PM ET / 21:20 UTC. Summary PR surface: Source +97, Tests +231. Total +328 across 3 files. Reproducibility: yes. source-level: current main releases the held write lock around provider prompt streaming without a same-session-file prompt turn guard, and the linked issue plus PR tests describe the cross-lane race. I did not run a live gateway repro because this review was read-only. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge Security Review detailsBest possible solution: Land the narrow prompt-window guard after focused maintainer review and green checks, while keeping the separate same-lane ALS follow-up in its own canonical issue. Do we have a high-confidence way to reproduce the issue? Yes, source-level: current main releases the held write lock around provider prompt streaming without a same-session-file prompt turn guard, and the linked issue plus PR tests describe the cross-lane race. I did not run a live gateway repro because this review was read-only. Is this the best way to solve the issue? Yes for the cross-lane race: the PR keeps the fix inside the embedded session-lock owner, adds focused cleanup and ordering regressions, and leaves the separate same-lane ALS issue to its own follow-up. AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against f4cfa012e117. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +97, Tests +231. Total +328 across 3 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
c22ae12 to
0fa3daa
Compare
|
ClawSweeper PR egg ✨ Hatched: 🥚 common Frosted Proofling Hatch commandComment Hatchability rules:
Rarity: 🥚 common. What is this egg doing here?
|
0fa3daa to
36f6ae7
Compare
|
@clawsweeper re-review\n\nAddressed the P1 stale prompt-holder lifecycle finding. The post-prompt compaction wait now uses a non-prompt release path, and the new regression covers release for compaction wait followed by withSessionWriteLock before a second same-file releaseForPrompt. Updated real behavior proof is in the PR body. |
|
🦞👀 Command router queued. I will update this comment with the next step. |
36f6ae7 to
a8cde4b
Compare
|
@clawsweeper re-review\n\nRebased onto current upstream/main to pick up the unrelated document extractor type-test fix, and pushed the stale prompt-holder lifecycle fix on the new head. Local post-rebase checks: targeted session-lock Vitest, pnpm check:test-types, oxfmt check, and git diff --check. |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
0e25c91 to
d716f20
Compare
d716f20 to
e84381f
Compare
|
Addressed the current ClawSweeper P1 queued prompt-turn cleanup finding in What changed:
Validation:
Author check before push: Raw Pulls API still reports @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Thanks @TurboTheTurtle for the original prompt-ownership guard PR. This was the first concrete implementation pass on the right invariant: concurrent embedded prompt windows need to coordinate by the resolved session JSONL, not only by logical session id/key. The final fix landed through #87159 in commit 3349fe2. It incorporates the same-session-file serialization direction from this PR, while extending the repair to the broader issue evidence: canonical file ownership, active embedded-run indexes by session file, same-file reply/recovery sibling checks, and diagnostic heartbeat recovery requests that preserve The landed PR has focused regression coverage plus AWS Crabbox proof for the heartbeat/recovery path that was missing from the earlier attempts. I’m closing this PR as superseded by the merged #87159 fix. Thanks again for pushing the initial guard and tests forward. |
Summary
Fixes #85913
Verification
node scripts/run-vitest.mjs src/agents/pi-embedded-runner/run/attempt.session-lock.test.tsupstream/main.pnpm check:test-typesupstream/main.node scripts/run-vitest.mjs src/agents/pi-embedded-runner/run/attempt.session-lock.test.ts src/logging/diagnostic-stuck-session-recovery.runtime.test.ts src/infra/heartbeat-runner.skips-busy-session-lane.test.ts src/agents/model-fallback.test.ts src/agents/failover-error.test.tsgit diff --checkpnpm exec oxfmt --check --threads=1 src/agents/pi-embedded-runner/run/attempt.session-lock.ts src/agents/pi-embedded-runner/run/attempt.session-lock.test.ts src/agents/pi-embedded-runner/run/attempt.tsReal behavior proof
withSessionWriteLock().fix/session-file-prompt-guard-85913, using the realacquireSessionWriteLockimplementation against a temporary session JSONL file.node --import tsx --input-type=modulewith an inline runtime script that created twocreateEmbeddedAttemptSessionLockControllerinstances for the same tempsession.jsonl; the first controller calledreleaseForSessionIdleWait()and then reacquired throughwithSessionWriteLock(), then the second controller calledreleaseForPrompt().{ "node": "v24.15.0", "platform": "darwin/arm64", "sessionFile": "<temp>/session.jsonl", "events": [ "first released for compaction wait without prompt holder", "first reacquired through withSessionWriteLock", "second released for prompt after first compaction wait", "second released after compaction path: true", "takeover first=false second=false" ] }withSessionWriteLock(); it did not wait on a stale prompt holder. Both controllers reportedhasSessionTakeover() === false.Authorship
Please preserve author attribution if this PR is squashed or reworked, or include:
Co-authored-by: Andy Ye <35905412+TurboTheTurtle@users.noreply.github.com>