Skip to content

fix(gateway): retry failed observer preparation - #133178

Merged
vincentkoc merged 1 commit into
mainfrom
fix/session-observer-preparation-cache
Aug 30, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/session-observer-preparation-cache

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where a transient session-observer model preparation failure
would be replayed from cache on the next attempt. The same failure exhausted
the two-attempt budget without retrying preparation, silently disabling model
observation for the run and publishing no digest even when preparation could
subsequently recover.

Why This Change Was Made

The repair lives at the preparedPromise cache owner. It retains the exact
preparation promise while it is pending or after it succeeds, but evicts that
same promise when it rejects or fulfills with { error }. The identity check
prevents an older settled failure from clearing a newer preparation.

Caller-level guards were rejected because they would duplicate cache policy
outside its owner. Failure-budget or scheduler changes were also rejected:
they would mask the poisoned cache instead of allowing the existing retry to
perform a fresh preparation.

Production LOC: +13/-3 (net +10) | Tests: +87/-44

User Impact

Session observation can recover after a transient preparation failure. Users
and operators no longer lose model-generated run status because one cached
failure was counted twice.

Evidence

  • Exact head: 23d82f1af1ff16e9d255fcb95137eeb634752d8c
  • Pre-fix reproduction: both rejected-promise and resolved-{ error } cases
    failed with one preparation call, zero completion calls, and zero broadcasts.
  • Post-fix observer coverage: 11 files, 97 tests passed.
  • pnpm tsgo:core: passed.
  • Assertion-safety and max-lines ratchets: passed against the merge base.
  • Targeted oxfmt, oxlint, and git diff --check: passed.
  • Exact changed-file gate passed every lane through core typecheck. Its
    tsgo:core:test lane is locally blocked by shared node_modules drift:
    the worktree resolves root [email protected] while ui/package.json declares
    [email protected]. Full-checkout CI owns that dependency-hydrated proof.
  • Final autoreview: no actionable findings, patch correct, confidence 0.98.
  • Independent review: no findings; best-fix verdict confirmed the cache owner
    and exact-promise eviction rather than caller guards or budget changes.

@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@vincentkoc vincentkoc self-assigned this Aug 30, 2026
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Aug 30, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 30, 2026 07:53
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 30, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 4:01 AM ET / 08:01 UTC.

ClawSweeper review

What this changes

The PR clears a failed session-observer model-preparation promise so the observer’s existing second attempt can prepare a fresh utility model and publish a digest.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. The branch repairs a current Gateway observer bug at the cache owner, and this MEMBER-authored, maintainer-labelled PR is not eligible for automated closure.

Priority: P1
Reviewed head: 23d82f1af1ff16e9d255fcb95137eeb634752d8c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The narrow cache-owner repair and focused coverage align with the scheduler’s documented retry path.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored Gateway repair is exempt from the external-contributor proof gate; its focused fault-injection tests remain supplemental evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored Gateway repair is exempt from the external-contributor proof gate; its focused fault-injection tests remain supplemental evidence.
Evidence reviewed 6 items Current-main defect: Current main awaits and retains state.preparedPromise without clearing a rejected or error-valued result, so the scheduler’s next attempt reuses the failed preparation.
Preparation failure contract: The preparation API explicitly returns either a prepared model or an object with error, and its implementation returns that error shape for model-resolution and auth failures.
Owner-boundary repair: The introduced hunk saves the exact shared promise and clears it only after rejection or the documented error result; successful and pending preparations remain shared.
Findings None None.
Security None None.

How this fits together

The Gateway session observer consumes agent lifecycle and tool events for a visible Control UI session. It prepares a utility model and publishes a generated run-status digest to subscribed operators.

flowchart LR
  A[Agent lifecycle and tool events] --> B[Gateway session observer]
  B --> C[Preparation promise cache]
  C --> D[Utility model]
  D --> E[Digest validation]
  E --> F[Subscribed Control UI sessions]
Loading

Before merge

  • Resolve merge risk (P1) - Production code grows by net 10 lines; the identity-guarded finalizer is justified by the cache’s pending, successful, and failed states, but retry policy should remain confined to this owner.
  • Resolve merge risk (P1) - The captured exact-head check rollup was still incomplete, so merge eligibility remains unverified.
  • Complete next step (P2) - This active maintainer-authored PR has a coherent repair and needs normal exact-head CI and maintainer merge handling, not an automated replacement.
Agent review details

Security

None.

PR surface

Source +10, Tests +43. Total +53 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 13 3 +10
Tests 2 87 44 +43
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 100 47 +53

Review metrics

Metric Value Why it matters
Production versus test LOC production +13/-3 (net +10); tests +87/-44 (net +43) The production growth is limited to cache-state cleanup; the test delta moves existing cancellation/timeout coverage and adds both preparation-failure modes.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the identity-guarded failed-promise eviction at the observer completion cache owner, preserving shared pending and successful preparation, then merge after exact-head CI completes.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the identity-guarded failed-promise eviction at the observer completion cache owner, preserving shared pending and successful preparation, then merge after exact-head CI completes.

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

Yes, from source: current main retains a rejected or error-valued preparation promise, so the next scheduled attempt reuses it and reaches the consecutive-failure limit.

Is this the best way to solve the issue?

Yes. Clearing only the identical settled failure at the cache owner preserves pending and successful sharing while allowing the existing retry to prepare anew.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against f120ed722654.

Labels

Label changes:

  • add P1: A transient preparation failure can exhaust the observer’s two-attempt budget and suppress a live run-status digest.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored Gateway repair is exempt from the external-contributor proof gate; its focused fault-injection tests remain supplemental evidence.

Label justifications:

  • P1: A transient preparation failure can exhaust the observer’s two-attempt budget and suppress a live run-status digest.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored Gateway repair is exempt from the external-contributor proof gate; its focused fault-injection tests remain supplemental evidence.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@vincentkoc

Copy link
Copy Markdown
Member Author

ClawSweeper before-merge disposition for exact head 23d82f1af1ff16e9d255fcb95137eeb634752d8c:

  • Production net +10: accepted and confined to the preparedPromise cache owner. The exact-promise identity guard evicts only settled rejection or fulfilled { error }; pending and successful preparation remain shared. No caller guard, scheduler, or failure-budget change was added.
  • Exact-head checks: resolved. The live rollup completed 306 checks with zero pending or failing conclusions.
  • Maintainer handling: resolved through the repo-native workflow. Review artifacts validate with zero findings, and scripts/pr review-tests 133178 src/gateway/session-observer-preparation.test.ts src/gateway/session-observer.test.ts passed. Proceeding through native prepare, merge verification, and auto-merge.

The full review reports no actionable findings and independently confirms this owner-level eviction as the best fix.

@vincentkoc
vincentkoc merged commit a3b5ce6 into main Aug 30, 2026
306 checks passed
@vincentkoc
vincentkoc deleted the fix/session-observer-preparation-cache branch August 30, 2026 08:06
@vincentkoc

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

gateway Gateway runtime maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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