Skip to content

test(gateway): wait for the withheld exec result before sweeping a yielded session - #204801

Merged
obviyus merged 1 commit into
mainfrom
fix/yield-sweep-owed-race
Nov 29, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/yield-sweep-owed-race

Conversation

@obviyus

@obviyus obviyus commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

src/gateway/session-yield-sweep.test.ts > "settles only an unreachable parked lifecycle (exec-completion)" fails intermittently on scheduled main (run 45403387860): expected undefined to be 'failed' at the final status check.

Since #204265, the yield sweep keeps a yielded session waiting while it has a stored owed exec result (shouldWake, session-yield-sweep.ts:45). When the exec completion's wake settles as cancelled, settleOwedExecWake withholds the owed row asynchronously: readPendingOwed and then withhold on the database worker. The test resolved the wake and advanced the fake clock straight away. When the sweep tick ran before withhold committed, the sweep still saw the pending row and correctly left the session waiting, so the status stayed unset.

Solution

Test-only change. After the wake settles, the test waits until shouldWake (the stored-row check the sweep itself uses) reports no owed result, then advances the clock. Product behavior is unchanged: the next sweep tick settles the session.

#204609 and #204621 do not touch this path. #204609 changes only session-restart-resume-custody.ts, which only the restart path imports. #204621 changes reply-operation backend readiness, which none of these modules use; the test's wake is mocked.

Impact

No change to production code or user behavior.

Evidence

  • Before: intermittent red on scheduled main with the assertion above: run 45403387860, and again in run 45849028735 (2026-11-26, checks-node-compact-large-14, after fix: skip idle chats when checking for stranded turns #205835), expected undefined to be 'failed' in the exec-completion case. The race mechanism (settleOwedExecWake withholds the owed row after the wake settles) is unchanged on current main.
  • Negative control (deterministic): with a 500 ms delay inserted before that withhold (local throwaway change), current main fails the exec-completion case 3/3 with the same assertion; with this change it passes 3/3.
  • Without the delay, interleaved runs of session-yield-sweep.test.ts with this change applied to current main: 20/20 green (main alone was also 20/20 locally; the natural race is rare).

Merge danger

Two-way door: test-only, a revert fully undoes it. Blast radius: one test file.

…elded session

A cancelled exec wake withholds its owed row asynchronously, and since #204265 the yield
sweep reads stored owed rows. The test advanced the clock before the row was withheld, so the
sweep could still see it and leave the session waiting.

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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. 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: passed.

What this changes

This PR waits for a cancelled exec wake’s stored result to be withheld before advancing the test’s maintenance clock.

Example: The exec-completion case cancels its wake before advancing maintenance by 60,000 milliseconds.

  • Before: Maintenance can still see the pending result and leave the lifecycle status undefined.
  • After: The test waits for the pending result to clear, then verifies that maintenance marks the unreachable lifecycle failed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, correct test repair supported by source tracing and successful head checks; deterministic baseline reproduction remains unestablished.
Proof confidence 🦐 gold shrimp (3/6) No user-visible production behavior changes; the existing scheduler/persistence test exercises the affected ordering, supported by reported focused passes and successful exact-head CI.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Test only · Worth it: Yes · Fix scope: Complete
User problem: An existing Gateway recovery regression test can fail intermittently while observing an intermediate database state.
Reason: The maintainer-authored repair restores the test’s required ordering while preserving the intended recovery behavior.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR makes a useful, minimal test synchronization repair still absent from current main; no actionable defects were found.

Reviewed head: f558fde93441793d5d254a5fbb31dbabd7b474d5

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway maintenance reads parked session lifecycles and their continuation sources, preserving resumable waits and recording failure when no continuation remains.

flowchart TD
  A[Test cancels exec wake] --> B[Async wake settlement]
  B --> C[Stored result withheld]
  C --> D[Test observes shouldWake false]
  D --> E[Maintenance clock advances]
  E --> F[Unreachable lifecycle fails]
Loading

Technical review

Best possible solution:

Keep the existing production owners and wait for completed stored-result settlement before advancing this test’s maintenance clock.

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

Source establishes the asynchronous settlement window behind the reported intermittent failure; no tests were executed during this read-only review, and a deterministic baseline failure is not established.

Is this the best way to solve the issue?

The existing stored-state reader provides the necessary synchronization without changing production behavior, adding a production test hook, or weakening the lifecycle assertion.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 51a07cc adds src/gateway/session-yield-sweep.test.ts:207 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 51a07cc9daa1; files: src/gateway/session-yield-sweep.test.ts)

PR surface

Tests +4. Total +4 across 1 file. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 4 0 +4
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 4 0 +4

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:

No label changes.

Label justifications:

  • 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 execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-24T17:36:54.629Z sha f558fde :: needs maintainer review before merge. :: none

Reviewed November 29, 2026, 9:49 AM ET / 14:49 UTC (Revision 2).

@THE-NAVVV THE-NAVVV left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

​

@daniel-lxs

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀

Re-review progress:

@obviyus
obviyus merged commit 777568e into main Nov 29, 2026
130 checks passed
@obviyus
obviyus deleted the fix/yield-sweep-owed-race branch November 29, 2026 17:08
@obviyus

obviyus commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 777568e.

The exec-completion case of session-yield-sweep.test.ts advanced the sweep clock before the cancelled wake's owed row was withheld, so the sweep correctly left the session waiting. It recurred on scheduled main on 2026-11-26. With a delayed withhold, main fails 3/3 and this change passes 3/3; 20/20 green without the delay.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 30, 2026
…elded session (openclaw#204801)

## Problem

`src/gateway/session-yield-sweep.test.ts` > "settles only an unreachable parked lifecycle (exec-completion)" fails intermittently on scheduled `main` (run 45403387860): `expected undefined to be 'failed'` at the final status check.

Since openclaw#204265, the yield sweep keeps a yielded session waiting while it has a stored owed exec result (`shouldWake`, `session-yield-sweep.ts:45`). When the exec completion's wake settles as `cancelled`, `settleOwedExecWake` withholds the owed row asynchronously: `readPendingOwed` and then `withhold` on the database worker. The test resolved the wake and advanced the fake clock straight away. When the sweep tick ran before `withhold` committed, the sweep still saw the pending row and correctly left the session waiting, so the status stayed unset.

## Solution

Test-only change. After the wake settles, the test waits until `shouldWake` (the stored-row check the sweep itself uses) reports no owed result, then advances the clock. Product behavior is unchanged: the next sweep tick settles the session.

openclaw#204609 and openclaw#204621 do not touch this path. openclaw#204609 changes only `session-restart-resume-custody.ts`, which only the restart path imports. openclaw#204621 changes reply-operation backend readiness, which none of these modules use; the test's wake is mocked.

## Impact

No change to production code or user behavior.

## Evidence

- Before: intermittent red on scheduled `main` with the assertion above: run 45403387860, and again in run 45849028735 (2026-11-26, `checks-node-compact-large-14`, after openclaw#205835), `expected undefined to be 'failed'` in the exec-completion case. The race mechanism (`settleOwedExecWake` withholds the owed row after the wake settles) is unchanged on current `main`.
- Negative control (deterministic): with a 500 ms delay inserted before that `withhold` (local throwaway change), current `main` fails the exec-completion case 3/3 with the same assertion; with this change it passes 3/3.
- Without the delay, interleaved runs of `session-yield-sweep.test.ts` with this change applied to current `main`: 20/20 green (main alone was also 20/20 locally; the natural race is rare).

## Merge danger

Two-way door: test-only, a revert fully undoes it. Blast radius: one test file.

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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

3 participants