fix(agents): scope compaction lock reentry to logical writer#88919
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 29, 2026, 8:00 AM ET / 12:00 UTC. Summary PR surface: Source +5, Tests +16. Total +21 across 2 files. Reproducibility: yes. at source level. Current main routes overflow recovery into direct compaction, direct compaction acquires the session lock without Review metrics: 1 noteworthy metric.
Stored data model 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 direct-compaction reentrant lock opt-in once maintainers accept this path as the same logical transcript writer, and keep broader inner-writer reentry review separate. Do we have a high-confidence way to reproduce the issue? Yes, at source level. Current main routes overflow recovery into direct compaction, direct compaction acquires the session lock without Is this the best way to solve the issue? Yes, conditionally. The runtime change is the narrowest immediate fix for direct compaction self-locking, but maintainers still need to accept that this direct compaction path is the same logical transcript writer before merge. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against db2488b6e3d6. Label changesLabel justifications:
Evidence reviewedPR surface: Source +5, Tests +16. Total +21 across 2 files. View PR surface stats
Acceptance criteria:
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
|
491de48 to
df6bc96
Compare
👍 Confirming + widening the scope (Feishu channel, 6.5.0)Hi @plexustech2006 — I hit the same root cause on 2026-06-11 in the Feishu channel (not just Telegram), so I want to confirm this is a broader issue and offer a slightly wider surface for the fix. Repro context
Wider surface than just preflight compactionWhile digging, I found the bug is not isolated to preflight compaction —
SuggestionThe fix may be better expressed as one of:
I just restarted the gateway ( — 🛠️ Self-hosted on macOS 26.5.1, gateway pid 32929, fresh after restart |
|
Behavioral proof from live production trajectory (embedded-agent-runner path, Claude Sonnet 4.6) Adding observed evidence that supports the fix here, plus a priority note for maintainers. What the trajectory shows: • Overflow #1 (15:20:09 EDT): no session.started in trajectory — lock held by the prior threshold compaction model call (still running). Gave up at 19:21:09.583Z, within 33ms of the threshold call's session.ended at 19:21:09.626Z. This is live behavioral confirmation of the same-process lock contention the PR addresses. The alternating pattern (every odd attempt hits contention, every even attempt gets through) directly results from the retry interval (~60s) being shorter than the model call duration (~143–187s). ClawSweeper noted "a behavior-level regression test would be stronger than the added source-string guard" — this is that behavioral data from production. Priority note for maintainers: |
|
This pull request has been automatically marked as stale due to inactivity. |
df6bc96 to
6343a47
Compare
6343a47 to
6ca6da9
Compare
5734d2a to
b3ccc7a
Compare
Replace the source-text guard with behavior-level coverage through the compaction harness. Co-authored-by: Plexus Technology <[email protected]>
Reuse only the matching logical transcript writer lock and keep unrelated same-process compaction serialized. Co-authored-by: Plexus Technology <[email protected]>
Co-authored-by: Plexus Technology <[email protected]>
Co-authored-by: Plexus Technology <[email protected]>
b3ccc7a to
300d409
Compare
|
Merged via squash.
|
…w#88919) * fix: allow preflight compaction to reenter session locks * chore: refresh proof checks * test(agents): cover compaction lock reentry Replace the source-text guard with behavior-level coverage through the compaction harness. Co-authored-by: Plexus Technology <[email protected]> * fix(agents): scope compaction lock reentry Reuse only the matching logical transcript writer lock and keep unrelated same-process compaction serialized. Co-authored-by: Plexus Technology <[email protected]> * test(agents): preserve lock runner generics Co-authored-by: Plexus Technology <[email protected]> * test(agents): preserve generic lock wrapper type Co-authored-by: Plexus Technology <[email protected]> --------- Co-authored-by: Plexus Technology <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
Summary
What Problem This Solves
Compaction can run inside an existing logical session writer. Reacquiring the non-reentrant physical lock there self-deadlocks until the 60-second timeout. A process-wide
allowReentrantopt-in avoids the timeout but is too broad: unrelated async work in the same gateway could then overlap transcript mutations.The final implementation adapts the existing matching
withOwnedSessionTranscriptWritescontext to the release-shaped lock used by direct compaction. No matching owner means the normal non-reentrant session lock remains mandatory.User impact
Context-pressure recovery no longer self-deadlocks when compaction is genuinely nested in the active logical writer. Independent turns and cleanup remain serialized, avoiding transcript races or lost messages.
Evidence
The contributor reproduced the failure on a live Linux gateway in a Telegram topic whose transcript exceeded its context window. Before the fix, preflight compaction repeatedly failed with a same-PID
session file locked (timeout 60000ms)error. After applying the original narrow hotfix, the exact topic completed successfully asTOPIC8_HOTFIX_OK, token usage fell from 144084 to 39386, and a lock-file sweep found no remaining*.jsonl.lockfiles.That live proof establishes the self-lock failure and recovery behavior. Maintainer review tightened the implementation from process-wide reentry to logical-owner-scoped reuse.
Validation
node scripts/run-vitest.mjs src/agents/embedded-agent-runner/compact.hooks.test.ts src/config/sessions/transcript.test.ts src/agents/embedded-agent-runner/run/attempt.session-lock.test.ts src/agents/session-write-lock.test.tsgit diff --checkNotes