Skip to content

fix: prevent chat stalls during progress-card saves - #167396

Merged
fuller-stack-dev merged 2 commits into
mainfrom
fix/progress-card-cleanup-deadlock
Oct 8, 2026
Merged

fuller-stack-dev merged 2 commits into
mainfrom
fix/progress-card-cleanup-deadlock

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes chat and other database writes becoming stuck when a progress-card save overlaps a history search.

User Impact

Messages and progress-card updates can finish during concurrent history reads. No configuration, schema, stored-data, or migration changes are required.

Why This Change Was Made

Writer-held session target discovery now uses a separate read-only worker lane, so its awaited cleanup cannot join a history task waiting for that same writer. The lane uses the existing lifecycle owner and starts on demand; the tradeoff is one additional lazy reader worker. FIFO ordering, current-target authorization, reader custody, and write settlement remain unchanged.

Evidence

  • A real progress-card/history regression timed out at the existing 120-second deadline before the fix and completed in about 1.04 seconds afterward.

  • All 153 focused tests passed, including write ordering, authority rollback, aliases and physical identity, lifecycle cleanup, cancellation, forks, incognito state, and uncertain-commit handling.

  • Core production types and all 27 core-test type graphs passed.

  • pnpm test src/gateway/progress-card-store.worker.test.ts --maxWorkers=1: 25.05 seconds wall time after the patch (7 tests, 6.47 seconds test time, including the 1.04-second regression). The failing-before command took 143.41 seconds including cold compilation. Hosted CI timing is not yet available.

  • Formatting, targeted lint, diff checks, and remaining changed-scope guards passed.

  • The full changed-check run stopped at an unused ClientVoiceToolEffect export in untouched src/talk/client-voice-session-store.ts. Its source matches the base exactly; no clean-baseline full scan was run, so this is unchanged-source attribution, not a claimed baseline reproduction.

  • Independent scoped review completed with no P0/P1 findings.

CI follow-up

The initial hosted changed-test job caught a stale interception in conversation-list.test.ts: its source-replacement case still waited for target discovery on the history lane. The same failure reproduced locally (1 failed, 9 passed). The fixture now intercepts the lane appropriate to each read phase, retaining real worker execution, file replacement, awaited cleanup, and the source-change rejection. All 10 conversation-list tests pass after this correction (node scripts/run-vitest.mjs src/gateway/conversation-list.test.ts --maxWorkers=1: 9.10 seconds wall time). No production change was needed. The initial failed CI remains failed; this is a repaired fixture, not a rerun-only claim.

Independent P0/P1 review of the test correction passed. A separate read-only sibling audit found no further stale discovery interceptions.

The correction also passes its Gateway test type graph, targeted lint, formatting, and changed-scope guards. The broader dead-export scan still stops on the same untouched voice export disclosed above.

@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@fuller-stack-dev
fuller-stack-dev marked this pull request as ready for review October 8, 2026 18:34
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Oct 8, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 2:58 PM ET / 18:58 UTC (Revision 2).

ClawSweeper review

What this changes

The branch separates writer-held session target discovery from history searches and updates affected regression fixtures.

Example: Save “Concurrent history” while searching history for “concurrent”.

  • Before: The save and search can wait on each other until timeout.
  • After: Both operations finish, and the saved progress card has revision 1.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported repair with meaningful real-worker regression coverage, whose proof remains an in-process harness.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: MEMBER authorship exempts this PR from the external-contributor proof gate, and the diff does not materially change authority. Supplied evidence reports progress-card save/history recovery through production owners and real workers in an in-process regression; it does not establish a shipped Gateway run. Source inspection verifies that no stored-data, schema, or configuration migration is introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Chat and progress-card updates can remain stuck when a save overlaps a history search.
Reason: The patch repairs a concrete circular wait while preserving the established persistence contract. One bounded lazy reader is proportionate to preventing stalled writes.

Merge readiness

✅ Ready for maintainer review

This PR addresses a source-supported deadlock that remains on current main. No actionable introduced defect was found, and the follow-up test correction preserves source-replacement coverage.

Priority: P1
Reviewed head: b6ba037247c845d904037df6a458c94876b0af05

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied before/after regression exercises production storage owners and real workers inside Vitest; no concurrent save/search run through a running Gateway is supplied. The reported base timeout and head completion were not rerun during this read-only review.
Agent review details

How this fits together

The Gateway saves progress cards through an ordered database writer. Read-only workers locate session databases and search history; their cleanup must finish without waiting on work that needs the same writer.

flowchart TD
  A[Progress-card save] --> B[Ordered database writer]
  B --> C[Separate target-discovery reader]
  C --> D[Save and finish reader cleanup]
  E[History search] --> F[Index-status request]
  F --> B
  D --> G[Writer released]
  G --> H[Save and search complete]
Loading

Technical review

Best possible solution:

Keep writer-held discovery and cleanup independent of history tasks under the existing database lifecycle owner.

Do we have a high-confidence way to reproduce the issue?

Yes, source establishes the writer-to-history-cleanup circular wait, and the supplied regression forces that ordering with real SQLite workers. This review did not execute it.

Is this the best way to solve the issue?

Yes, separating discovery in the shared resource owner removes the circular dependency while preserving FIFO, target identity, authorization, and caller-selected read lanes.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d81169b0c996.

Provenance checked

Testing

Proof path: in-process harness. Added test files: 3.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The introduced production change selects a dedicated discovery lane by default while retaining explicit caller-selected lanes and existing target-currentness checks. (src/config/sessions/session-store-target-runtime.ts:175, b6ba037247c8)
  • Lifecycle integration: The additional singleton reader uses the existing pool constructor and participates in whole-runtime closure, exact database cleanup, idle retirement, and critical-memory-pressure retirement. (src/config/sessions/session-transcript-worker-resources.ts:138, b6ba037247c8)
  • Concrete deadlock regression: The regression wraps actual worker execution to hold card-save settlement until a history search requests writer-backed index status, then asserts both operations settle and reads back revision 1. The fully read PR body reports a 120-second pre-fix timeout and approximately 1.04-second post-fix completion; these runs were not repeated during this read-only review. (src/gateway/progress-card-store.worker.test.ts:117, b6ba037247c8)
  • Follow-up fixture correction: The only change since the previously reviewed head selects the discovery lane for the target phase and retains the history lane for conversation rows. Both phases still execute the real worker and reject a replacement source; the body reports all 10 conversation-list tests passing after the correction. (src/gateway/conversation-list.test.ts:476, b6ba037247c8)
  • Current-main necessity and overlap: Current main still leaves the target-discovery lane unspecified, selecting the history default. The five touched source/test files have no changes between the merge base and fetched main; the documentation changes are separate insertions. The supplied test merge is stale and was not used to claim integration safety. (src/config/sessions/session-store-target-runtime.ts:174, d81169b0c996)
  • Existing persistence contract: refactor(agents): persist progress cards through the agent writer #164458 established exact-store FIFO, physical identity capture, live transaction/commit authorization, and settlement without replaying unknown outcomes. This patch changes reader scheduling without changing those checks, SQL commands, schemas, serialized data, or configuration. (src/gateway/progress-card-store.ts:222, b6ba037247c8)

Likely related people:

  • Peter Steinberger: Raw commit c4d2684 adds src/config/sessions/session-store-target-runtime.ts:20 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c4d2684a2762; files: src/config/sessions/session-store-target-runtime.ts)

PR surface

Source +7, Tests +71, Docs +9. Total +87 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 2 9 2 +7
Tests 3 82 11 +71
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 100 13 +87

Review metrics

Metric Value Why it matters
Reader capacity 1 additional lazy singleton worker The bounded additional reader removes the circular dependency and shares existing resource retirement.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The source-supported circular wait can stall progress-card persistence and other writes sharing the session database writer.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-08T18:40:32.883Z sha c536ac6 :: needs maintainer review before merge. :: none

@fuller-stack-dev
fuller-stack-dev enabled auto-merge (squash) October 8, 2026 18:44
@fuller-stack-dev
fuller-stack-dev merged commit b2d00be into main Oct 8, 2026
126 of 127 checks passed
@fuller-stack-dev
fuller-stack-dev deleted the fix/progress-card-cleanup-deadlock branch October 8, 2026 19:04
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant