Skip to content

fix(gateway): finish successful sessions after timestamp races - #119752

Merged
Patrick-Erichsen merged 3 commits into
mainfrom
pe/fix-session-lifecycle-run-ownership
Aug 6, 2026
Merged

Patrick-Erichsen merged 3 commits into
mainfrom
pe/fix-session-lifecycle-run-ownership

Conversation

@Patrick-Erichsen

@Patrick-Erichsen Patrick-Erichsen commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #119407

What Problem This Solves

Fixes an issue where a successful session could remain marked as running when its terminal lifecycle event arrived with a timestamp older than a newer same-run metadata write. This could leave the operator-visible session state stuck even though the agent run had already completed.

Why This Change Was Made

Session lifecycle state now records a private durable run owner in the existing session entry JSON. Accepted starts and recovery runs claim that owner, and terminal events from the same run can settle the session despite timestamp races; events from another session or run remain fenced as stale.

Ownership is explicitly preserved, transferred, or cleared across yielded runs, restart recovery, pending-final dispatch, reset, rotation, fork, checkpoint, terminal, and forced-clear paths. Public Gateway, session, and plugin projections strip this internal field. This uses the existing entry_json storage, so there is no SQLite DDL, schema-version, Gateway protocol, or plugin SDK change.

The QA restart scenario now treats already-delivered handoffs as settled: after restart it proves there is no replay or synthetic interruption output, then uses a new durably delivered task as the observation boundary and proves post-restart completion exactly once. Its previous interruption expectation depended on the stuck-running state fixed here.

The regression was introduced by #117731 (7c1d5dc7ef5855800894ad04fbf1922e0e16bf34). Thanks to @harjothkhara and #119456 for independently identifying durable run identity as the key missing state; this maintainer repair was derived independently and extends the ownership model across recovery and cleanup boundaries.

User Impact

Completed sessions reliably stop showing as running even when same-run persistence events arrive out of timestamp order. Older or unrelated lifecycle events still cannot overwrite newer session state.

Evidence

  • On the rebase-equivalent pre-publish patch, Blacksmith Testbox wrapper-synced source and passed 365 focused tests across 5 Vitest shards (keepalive workflow metadata). The Actions page is transport metadata and can show cancelled keepalive jobs; the command result, not the workflow conclusion, is the proof.
  • Independent wrapper-synced verification passed 233 focused tests (keepalive workflow metadata).
  • Wrapper-synced static proof passed pnpm tsgo:core and pnpm tsgo:core:test (keepalive workflow metadata).
  • git diff --check origin/main...HEAD passed locally.
  • Branch autoreview reported no findings and judged the patch correct with 0.97 confidence.
  • Focused QA scenario-catalog validation passed 13/13 tests after correcting the restart contract exposed by hosted CI.
  • Dedicated Blacksmith Testbox proof passed the complete subagent-completion-direct-fallback scenario (1/1) on the runtime- and QA-equivalent preceding head; the final head only splits its persistence test to satisfy the lint budget (Testbox transport run).
  • Focused coverage includes the original timestamp race, mismatched session/run rejection, yielded ownership preservation, terminal cleanup, reset/rotation/fork/checkpoint cleanup, restart-recovery transfer/failure, pending-final handoff, forced clear, and private projection filtering.

The changed-gate wrapper could not start in two Testbox attempts because remote rsync cleanup timed out on a busy node_modules; the directly relevant static lanes above passed. Native hosted CI and the guarded prepare step are the authoritative exact-head merge gates. No fresh authenticated live Codex or channel proof was run for this internal lifecycle-state repair.

Production code is +149/-56 (net +93); tests and QA evidence are +323/-64 (net +259). The production increase establishes one durable owner boundary and makes its lifecycle transitions explicit across all session mutation paths rather than compensating at the terminal-event consumer.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Aug 5, 2026
@Patrick-Erichsen
Patrick-Erichsen marked this pull request as ready for review August 5, 2026 21:58
@Patrick-Erichsen
Patrick-Erichsen force-pushed the pe/fix-session-lifecycle-run-ownership branch from 4d2f01c to 040e26f Compare August 5, 2026 21:59
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@Patrick-Erichsen

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head ea3cf19713423f87c59df2ee253ec0b7a9ad3082, but the PR head is now b18fe219539a7fdeb83c26ff0eacfeb167424e28. Its old verdict and PR readiness labels are no longer current.

Next step
Run or wait for a fresh ClawSweeper review on the current PR head.

Review history (1 earlier review cycle)
  • reviewed 2026-08-05T22:37:03.274Z sha f40a7a08f57f8a75ecd24712d00c89cddc3b7e0e :: needs maintainer review before merge. :: none

@Patrick-Erichsen
Patrick-Erichsen force-pushed the pe/fix-session-lifecycle-run-ownership branch from f40a7a0 to b18fe21 Compare August 5, 2026 22:41
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 5, 2026
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 5, 2026
@Patrick-Erichsen
Patrick-Erichsen merged commit 678a3c1 into main Aug 6, 2026
131 checks passed
@Patrick-Erichsen
Patrick-Erichsen deleted the pe/fix-session-lifecycle-run-ownership branch August 6, 2026 00:24
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
…law#119752)

* fix(gateway): correlate session lifecycle by run

* test(qa): expect settled handoffs to survive restart quietly

* test(agents): split embedded run persistence coverage
vincentkoc added a commit to VACInc/openclaw that referenced this pull request Aug 6, 2026
…cope

* origin/main: (24 commits)
  fix(backup): skip transient gateway lock databases (openclaw#119782)
  test(agents): use canonical auth session fixtures (openclaw#119821)
  fix(memory): keep QMD file hints after stale docid misses (issue openclaw#113041) (openclaw#113515)
  test(doctor): align fast-path repair contracts (openclaw#119812)
  perf(agents): index subagent recovery ownership (openclaw#119793)
  fix(gateway): keep chat startup off catalog discovery (openclaw#119742)
  fix(test): keep TUI PTY suites in their owner lane (openclaw#119787)
  docs: correct dashboard auth precedence (openclaw#119785)
  docs: document control ui owner handoff
  fix: grant host-authorized control ui owner access
  fix(worktrees): preserve registered roots during orphan cleanup (openclaw#119709)
  fix(matrix): prevent shared client key collisions (openclaw#119667)
  fix(diagnostics-otel): propagate exported span context (openclaw#112283)
  fix(worker): isolate state observer failures (openclaw#117507)
  fix(qa): attest realized profile executions (openclaw#119761)
  fix(gateway): finish successful sessions after timestamp races (openclaw#119752)
  fix(agents): fence restart recovery lifecycle (openclaw#119776)
  fix(ui): preserve chat history and active run timing (openclaw#119729)
  improve(ollama): reduce inactive startup cost (openclaw#119745)
  improve(gateway): defer inactive plugin runtime imports (openclaw#119733)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: qa-lab gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L 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.

[Bug]: same-run terminal lifecycle event is dropped as stale, leaving successful sessions running

1 participant