Skip to content

fix(dashboard): status refresh no longer stalls on another request's token mint - #2156

Merged
obviyus merged 1 commit into
mainfrom
fix/status-refresh-deadline
Nov 5, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/status-refresh-deadline

Conversation

@obviyus

@obviyus obviyus commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Problem

/api/status keeps serving a stale snapshot. #2154 removed the request that timed out, but on 2026-11-05 production refreshes still ended at the 18s STATUS_REFRESH_TIMEOUT_MS deadline. wrangler tail on clawsweeper-status while I polled /api/status:

/api/status ok 18000  status_refresh_deadline {"pending_phases": ["github_auth", "refresh"]}
/api/status ok 18000  status_refresh_deadline {"pending_phases": ["github_auth", "refresh"]}
/api/status ok 18786
/api/status ok  9266   <- the one refresh that completed

An earlier deadline in the same session also logged the Workers warning "A promise was resolved or rejected from a different request context … Continuations for that request … have been canceled." The same refresh path finishes in 7–9s locally against live GitHub.

Cause

githubAppTokenCache is isolate-wide and stored in-flight mint promises ({ token: "", promise }), and any later request reused them. Workers cancels a request's I/O when that request ends. If a short request (a webhook, an internal call) starts a mint and finishes first, the mint never settles. Every later status refresh needing that scope then awaits it until the deadline. The entry is never removed either: the expiry sweep skipped promise entries, and only a rejection deleted them. So the isolate stays stale until it's recycled.

Fix

  • Share only settled tokens across requests.
  • Deduplicate in-flight mints only within one StatusCollection, which owns their I/O, so a single refresh's fan-out still mints once per scope.
  • Callers outside a status refresh mint their own token when none is cached.

Tests

  • New: a token mint stranded by another request cannot stall later reads fails on main ("later read stalled") and passes here.
  • Updated: status timeout does not cancel shared GitHub App token acquisition used to assert that a second request reused the status refresh's in-flight mint. That's exactly the sharing that strands in Workers, and Node's test runner can't model request-scoped I/O cancellation. It now asserts that the other reader gets its own token without waiting on the stalled mint, and that a later status reuses the settled token.
  • test/dashboard-*.test.ts and test/github-etag-read-broker.test.ts: 856/856 pass, run twice. lint:dashboard, lint:scripts, dashboard tsc and oxfmt are clean.

After merge and deploy, I'll check that /api/status regenerates within its 60s TTL and that the tail stops logging github_auth at the deadline.

…token mint

The isolate-wide GitHub App token cache stored in-flight mint promises and
handed them to later requests. Workers cancels a request's I/O when that
request ends, so a mint started by a short request (a webhook, an internal
call) could never settle, and every later status refresh that needed the
same scope awaited it until the 18s deadline. Production tails show those
refreshes ending at the deadline with github_auth pending, which leaves
/api/status serving a stale snapshot.

Share only settled tokens across requests, and deduplicate in-flight mints
within one status collection, which owns their I/O.

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

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

@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 priority bug or improvement 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 5, 2026
@clawsweeper

clawsweeper Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR shares completed GitHub App tokens globally while restricting pending token acquisition to one status collection.

Example: A request strands a token mint for openclaw/clawsweeper Actions reads before another status refresh begins.

  • Before: The refresh reuses the stranded promise and reaches its 18-second deadline.
  • After: The refresh starts an independent mint, sharing its result with readers in that collection.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is focused and source review found no actionable defect, but mocked validation does not establish the required runtime behavior.
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: Dashboard status remains stale when later refreshes await a token mint stranded by another request.
Reason: The host establishes owner-approved direction, and restoring status refresh progress has clear value within the existing authentication and polling contract.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: main still shares pending token mints across requests, and this focused repair addresses a credible cause of stale dashboard status without a definite introduced correctness defect.

Priority: P2
Reviewed head: 14a345d7941ca80bde402650c52a79ba6d151f08

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Missing a current-head Workers runtime trace showing a later /api/status refresh recovering after another request strands a same-scope token mint.
Agent review details

How this fits together

The dashboard Worker authenticates server-side GitHub reads, collects workflow and queue telemetry, and returns sanitized cached snapshots through /api/status.

flowchart LR
  A[Dashboard poll] --> B[Status collection]
  B --> C[Collection token mints]
  C --> D[GitHub App API]
  D --> E[Completed token cache]
  E --> F[GitHub telemetry reads]
  F --> G[Public status snapshot]
Loading

Technical review

Best possible solution:

Keep completed-token reuse and scope enforcement in the existing authentication owner, with pending acquisition owned by each status collection.

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

Main demonstrably reuses an indefinitely pending mint, and the report supplies matching github_auth deadline logs; the Workers request-cancellation trigger was not independently reproduced.

Is this the best way to solve the issue?

The patch uses the existing collection lifetime and token-scope owner, removing the persistent pending-promise dependency without adding a parallel authentication path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Global pending-token reuse changes intended behavior with a stated reason (dff7493: The original triage dashboard added server-side GitHub App enrichment with completed-token caching and shared pending acquisition; this PR explains why pending acquisition cannot safely cross Workers requests.)
  • Scoped token cache and failure cleanup keeps the original intent (fix: scope ClawSweeper App tokens to explicit repositories and least privilege #2063: The scoped-token refactor separates repository and permission authority, expires completed entries, and recovers rejected tokens; these contracts remain, while failed local acquisitions now clear only their collection entry.)
  • Authentication sharing asserted by status lifetime coverage changes intended behavior with a stated reason (fix(dashboard): recover status polling after stalled reads #1599: The lifetime repair intentionally preserved shared authentication while bounding status waits; this PR explicitly replaces cross-request pending sharing because the Node fixture did not model Workers cancellation.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Verified introduced change: The pinned diff removes pending promises from the isolate-wide token cache and attaches pending acquisitions to the existing StatusCollection; repository and permission cache keys remain unchanged. (dashboard/worker.ts:9598, 14a345d7941c)
  • Current main retains the failure path: Main returns cached pending promises before starting another acquisition, while its expiry sweep excludes those entries; a promise that never settles can therefore block subsequent same-scope reads indefinitely. (dashboard/worker.ts:9600, 49ffa8bdf0a0)
  • Existing security contract preserved: fix: scope ClawSweeper App tokens to explicit repositories and least privilege #2063 established explicit repository and permission scopes, expiry handling, and revoked-token recovery; this PR retains those owners and changes acquisition lifetime. (dashboard/worker.ts:9583, 5af774151f17)
  • Related production incident: fix(dashboard): stop status refresh timing out on unfiltered run listing #2154 removed a separate slow unfiltered run listing; its live-GitHub measurements do not exercise this PR's pending-token isolation. (7533acb6494d)
  • Supplied validation and discussion: The complete PR body matches the supplied text associated with sourceRevision 3f3967bbbce3518b73ed30aa2f246438618e5dcf549ce77f5959edef2cb993f5; it supplies pre-fix production logs and mocked regression results, with post-deployment verification deferred, and both comments are automation status messages. (test/dashboard-app-token-scoping.test.ts:247, 14a345d7941c)
  • Repository policy and checkout: The complete root AGENTS.md applies; no nested policies, maintainer-notes directory, or pr-simplify skill were found for the changed paths, the required changelog fragment is present, and the checkout remains clean. (AGENTS.md, 14a345d7941c)

Likely related people:

  • Peter Steinberger: Raw commit 5af7741 adds dashboard/worker.ts:9411 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5af774151f17; files: dashboard/worker.ts)
  • Vincent Koc: Raw commit f8ec10f adds dashboard/worker.ts:663 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f8ec10f29bde; files: dashboard/worker.ts)
  • brokemac79: Raw commit dff7493 adds dashboard/worker.js:1509 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: dff74930c900; files: dashboard/worker.js)
  • Ayaan Zaidi: Raw commit 7533acb adds dashboard/worker.ts:6812 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7533acb6494d; files: dashboard/worker.ts)

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.

Review metrics

Metric Value Why it matters
Change size Production +13/-17; tests +47/-4; changelog +1 The implementation shrinks while adding distinct stranded-acquisition and request-isolation coverage.

Labels

Label changes:

  • add P2: Stale dashboard telemetry impairs operational visibility, with no demonstrated interruption to review execution or user data.
  • 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: Stale dashboard telemetry impairs operational visibility, with no demonstrated interruption to review execution or user data.
  • 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 5, 2026, 12:58 AM ET / 05:58 UTC.

@obviyus
obviyus merged commit 014aa26 into main Nov 5, 2026
39 checks passed
@obviyus
obviyus deleted the fix/status-refresh-deadline branch November 5, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant