Skip to content

fix(gateway): stop run-end transcript reads once the Gateway drains or closes - #204544

Merged
obviyus merged 1 commit into
mainfrom
fix/e2e-backfill
Nov 24, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/e2e-backfill

Conversation

@obviyus

@obviyus obviyus commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Problem

During a Gateway restart or stop, a run that ends after the agent database's clean-close receipt can reopen the sealed store. test/gateway-restart-resume.e2e.test.ts ("restart markers survive graceful shutdown (blocked store: false)") catches it: a session.rowTranscript.backfill reservation starts after the clean-close (expected true to be false at the [close-backfill-proof] check). No scheduled CI lane runs this file.

Cause: #204281 added readVisibleSessionActivityAt. Every run end calls it, and it uses backfillSessionRowTranscriptFields with no signal. #188976 fenced only the session-row projection queue. Shutdown aborts the active runs, those runs end, and each run end then opens the store again.

Solution

The drain and shutdown fence moves into backfillSessionRowTranscriptFields, the function that opens the store. Every caller gets it, including the run-end read. The signal parameter is removed, because its only caller (the projection queue) passed the same two signals.

Impact

  • A run that ends while the Gateway drains or closes does not advance unread. The run-end read already treats a failure as "unread unchanged". Accepted edge case: a visible reply that lands during shutdown does not light the unread dot.
  • No change outside shutdown.
  • Production: +16 / −11 lines in 2 files.

Evidence

  • Base (main), the same filtered case: the [close-backfill-proof] check fails in cycle 1.
  • Head: cycle 1 passes the check (a run free of a local port probe that sends GET / to new listeners and breaks the fixture's JSON parse). Unit tests session-row-transcript-backfill.test.ts (16) and session-accessor.sqlite-maintenance-read.test.ts (8) pass. pnpm tsgo:core passes.
  • The e2e case is still red on head, at a later step: in cycle 2, a queued input is cancelled at restart (HANDLED_QUEUED_BEFORE_RESTART_2_1). That failure also occurs on 57dd84bd, before fix(sessions): unread advances only when a run ends with a new visible reply #204281, so it has a separate cause. It is tracked separately.

…r closes

Since #204281 every run end reads its transcript through the row backfill without a
close fence, so runs that end during shutdown reopened the sealed agent database after
its clean-close receipt. Fence every backfill read in the function that opens the store.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 24, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Nov 24, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 24, 2026
@clawsweeper

clawsweeper Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes every optional session transcript backfill consume the Gateway’s existing drain and shutdown signals.

Example: An active run finishes after the Gateway has begun shutdown.

  • Before: Its run-end activity read can start another transcript backfill after database clean-close.
  • After: The shared reader refuses the optional backfill and leaves unread activity unchanged.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation is source-consistent, but the available submission does not support a runtime-proof pass.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Gateway shutdown can start optional transcript work after database clean-close.
Reason: The collaborator-authored direction restores the established shutdown contract and explicitly accepts the limited unread consequence.

Regression provenance

Regression provenance — verified: source commit 7986fe168800 by Ayaan Zaidi; canonical PR #204281 (blame-to-merge-commit).

Merge readiness

✅ Ready for maintainer review

Keep open: this collaborator-authored PR addresses a current-main shutdown regression with a focused shared-owner fix; source review found no introduced code defect.

Priority: P2
Reviewed head: 81e231ffb8e1a0d90bba5c6fb22b8a11f9ea64e8

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supply redacted output from the described Gateway shutdown run showing clean-close, no subsequent backfill reservation, and process exit; remove IPs, credentials, phone numbers, and non-public endpoints.
Agent review details

How this fits together

Run-end finalizers and session-row enrichment request bounded transcript facts through a shared reader, which reserves the database writer and dispatches a worker operation.

flowchart TD
  A[Run end finalizers] --> C[Shared transcript reader]
  B[Session row enrichment] --> C
  D[Gateway lifecycle signals] --> C
  C --> E[Database writer admission]
  E --> F[Transcript worker]
  F --> G[Preview and activity facts]
Loading

Technical review

Best possible solution:

Keep the shutdown check in the shared backfill reader, retain queue scheduling checks, and let the existing database owner settle accepted work.

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

Current main’s run-end helper reaches the backfill without cancellation, while the earlier shutdown check depends on a caller-supplied signal; the reported restart assertion matches this path, but this read-only review executed no target code.

Is this the best way to solve the issue?

The patch is the smallest complete source repair: it applies existing lifecycle policy at the shared operation and removes the superseded caller argument without adding another owner or changing worker settlement.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Optional transcript work during shutdown keeps the original intent (c75a8a8: Stop queued optional previews from reopening databases after clean-close while preserving accepted-work settlement.)
  • Run-end visible activity reads keeps the original intent (7986fe1: Advance unread only when the transcript contains a newer visible assistant reply, treating read failure as unchanged activity.)

Testing

Proof path: none.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit c75a8a8 adds src/gateway/session-row-transcript-backfill.ts:74 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c75a8a821e50; files: src/gateway/session-row-transcript-backfill.ts)
  • Ayaan Zaidi: Raw commit 7986fe1 adds src/gateway/session-row-transcript-backfill.ts:116 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7986fe168800; files: src/gateway/session-row-transcript-backfill.ts)

PR surface

Source +5. Total +5 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 16 11 +5
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 16 11 +5

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: The source-established regression permits optional database work during shutdown, but the supplied evidence establishes no released-user outage.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The source-established regression permits optional database work during shutdown, but the supplied evidence establishes no released-user outage.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab 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 execution lanes are retired.

Reviewed November 24, 2026, 4:42 AM ET / 09:42 UTC.

@obviyus
obviyus merged commit 76e2021 into main Nov 24, 2026
201 of 203 checks passed
@obviyus
obviyus deleted the fix/e2e-backfill branch November 24, 2026 10:30
tideclaw-bot pushed a commit that referenced this pull request Nov 25, 2026
…r closes (#204544)

## Problem

During a Gateway restart or stop, a run that ends after the agent database's clean-close receipt can reopen the sealed store. `test/gateway-restart-resume.e2e.test.ts` ("restart markers survive graceful shutdown (blocked store: false)") catches it: a `session.rowTranscript.backfill` reservation starts after the clean-close (`expected true to be false` at the `[close-backfill-proof]` check). No scheduled CI lane runs this file.

Cause: #204281 added `readVisibleSessionActivityAt`. Every run end calls it, and it uses `backfillSessionRowTranscriptFields` with no signal. #188976 fenced only the session-row projection queue. Shutdown aborts the active runs, those runs end, and each run end then opens the store again.

## Solution

The drain and shutdown fence moves into `backfillSessionRowTranscriptFields`, the function that opens the store. Every caller gets it, including the run-end read. The `signal` parameter is removed, because its only caller (the projection queue) passed the same two signals.

## Impact

- A run that ends while the Gateway drains or closes does not advance unread. The run-end read already treats a failure as "unread unchanged". Accepted edge case: a visible reply that lands during shutdown does not light the unread dot.
- No change outside shutdown.
- Production: +16 / −11 lines in 2 files.

## Evidence

- Base (`main`), the same filtered case: the `[close-backfill-proof]` check fails in cycle 1.
- Head: cycle 1 passes the check (a run free of a local port probe that sends `GET /` to new listeners and breaks the fixture's JSON parse). Unit tests `session-row-transcript-backfill.test.ts` (16) and `session-accessor.sqlite-maintenance-read.test.ts` (8) pass. `pnpm tsgo:core` passes.
- The e2e case is still red on head, at a later step: in cycle 2, a queued input is cancelled at restart (`HANDLED_QUEUED_BEFORE_RESTART_2_1`). That failure also occurs on `57dd84bd`, before #204281, so it has a separate cause. It is tracked separately.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 76e2021)
Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 25, 2026
…r closes (openclaw#204544)

## Problem

During a Gateway restart or stop, a run that ends after the agent database's clean-close receipt can reopen the sealed store. `test/gateway-restart-resume.e2e.test.ts` ("restart markers survive graceful shutdown (blocked store: false)") catches it: a `session.rowTranscript.backfill` reservation starts after the clean-close (`expected true to be false` at the `[close-backfill-proof]` check). No scheduled CI lane runs this file.

Cause: openclaw#204281 added `readVisibleSessionActivityAt`. Every run end calls it, and it uses `backfillSessionRowTranscriptFields` with no signal. openclaw#188976 fenced only the session-row projection queue. Shutdown aborts the active runs, those runs end, and each run end then opens the store again.

## Solution

The drain and shutdown fence moves into `backfillSessionRowTranscriptFields`, the function that opens the store. Every caller gets it, including the run-end read. The `signal` parameter is removed, because its only caller (the projection queue) passed the same two signals.

## Impact

- A run that ends while the Gateway drains or closes does not advance unread. The run-end read already treats a failure as "unread unchanged". Accepted edge case: a visible reply that lands during shutdown does not light the unread dot.
- No change outside shutdown.
- Production: +16 / −11 lines in 2 files.

## Evidence

- Base (`main`), the same filtered case: the `[close-backfill-proof]` check fails in cycle 1.
- Head: cycle 1 passes the check (a run free of a local port probe that sends `GET /` to new listeners and breaks the fixture's JSON parse). Unit tests `session-row-transcript-backfill.test.ts` (16) and `session-accessor.sqlite-maintenance-read.test.ts` (8) pass. `pnpm tsgo:core` passes.
- The e2e case is still red on head, at a later step: in cycle 2, a queued input is cancelled at restart (`HANDLED_QUEUED_BEFORE_RESTART_2_1`). That failure also occurs on `c28cebe5`, before openclaw#204281, so it has a separate cause. It is tracked separately.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS 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