Skip to content

refactor: own GitHub runtime state per command - #1898

Merged
obviyus merged 3 commits into
mainfrom
cleanup/row3-github-runtime
Oct 10, 2026
Merged

obviyus merged 3 commits into
mainfrom
cleanup/row3-github-runtime

Conversation

@obviyus

@obviyus obviyus commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Row 3 slice 4a removes createGitHubRuntime and untrustedCodexEnvForTest; the shipped CLI imports runtime operations directly. Budgets, credential inspection/fallback reservations, and retained ETag responses live in one command-lifetime withGitHubRun data scope. Async continuations retain their own budget; nested budgets do not reset command caches. No collaborator registry or process-global response cache is introduced.

The lead approved AsyncLocalStorage for data only rather than threading unrelated owner state through every existing read. Execution/context factories remain for the dependent slice: #1905. All current runtime-factory callers migrate, including executable-gh tests and frozen proof drivers. Historical factory adapters exist only in explicit old-source proof paths.

Current head: 6f8ca6631af750e9fbac3c7b2f9782778743e510, rebased on origin/main c2753fb49e2542716365a167b055aac6709f9040, including the typed review-record reader migration. This revision changes only the hydration proof driver after the rebase.

Hosted finding disposition

The P2 is fixed at the observed boundary. The proof now catches the result of ghJson/ghWithRetry, which normalizes an expired request to GitHubOperationDeadlineError, not the raw subprocess ETIMEDOUT. Its recorder stores name and deadlineAt, and the assertion compares the exact deadline admitted for that metadata request. It does not manufacture a subprocess error code.

Cancellation remains independently required: one bounded child, no metadata response or completed delay, observed SIGTERM, a matching child exit, no surviving exact PID/start-time identity, no fetches, and all originally missing blobs still missing. No assertion was skipped or weakened.

Fresh local review also identified that archived source roots still export the removed factory. The driver now adapts only those old source roots with their historical factory; current code still uses plain imports. Both historical baseline and current candidate modes were exercised successfully (pueue 1644). Exact-head Linux cancellation proof and codex review --base origin/main passed in 1646, with no actionable findings.

Base-failure evidence for the new isolation tests

Built unchanged main code at c2753fb49e2542716365a167b055aac6709f9040 and ran the two new tests' unchanged bodies against it (pueue 1638). Only test imports were mechanically redirected through a historical API adapter: one real createGitHubRuntime instance uses runText/runTextConcurrently; the new scope call maps to main's unscoped command entry. No production code, assertions, transport, or result classification was replaced.

Command:

node --test --test-name-pattern='run state and runtime budgets stay isolated|runtime ETags revalidate through gh and keep retained bodies scoped to one run' test/apply-runtime-budget.test.1898.ts test/github-etag-read-broker.test.1898.ts

Observed baseline output:

✖ run state and runtime budgets stay isolated across asynchronous commands
  AssertionError: assert.ok(runtime.githubCommandTimeoutMs() > 0)
  actual: false; expected: true
✖ runtime ETags revalidate through gh and keep retained bodies scoped to one run
  actual:   [ 'lookup', 'store', 'store' ]
  expected: [ 'lookup', 'store', 'store', 'lookup', 'confirm' ]
tests 2; pass 0; fail 2; cancelled 0; skipped 0
Expected baseline test failure exit: 1

The same two tests pass on this branch within the 266/266 focused run (pueue 1637). This is behavior failure on main, not a missing-export or import-error demonstration. Reproduction files are retained in /tmp/clawsweeper-1898-main/test/*1898.ts and dist/runtime-isolation-adapter.js; the command and complete output are in the pueue receipt.

Shipped-CLI before/after proof

Claim: command scoping preserves repository routing, JSON responses, transient and malformed-JSON retries, and terminal throttling. Surface: actual node dist/clawsweeper.js reserve-review-lease children against executable gh fixtures, with isolated environment and request logs. Baseline is the main SHA above; candidate is the rebased branch's identical production source (the final follow-up changes only the proof driver). Pueue 1642 passed all 8/8 comparisons. The first replay used macOS's noncanonical /tmp path and did not enter the CLI; the successful replay uses /private/tmp and observes all requests.

Inline comparison output, derived from both arms' retained JSON/stdout/request traces:

[
  {
    "scenario": "closed",
    "repo": "openclaw/openclaw",
    "before": {
      "exit": 0,
      "requests": 1,
      "stdout": "{\"status\":\"superseded\",\"reason\":\"item_not_open\",\"state\":\"closed\"}",
      "errorClass": null
    },
    "after": {
      "exit": 0,
      "requests": 1,
      "stdout": "{\"status\":\"superseded\",\"reason\":\"item_not_open\",\"state\":\"closed\"}",
      "errorClass": null
    },
    "requestTraceIdentical": true
  },
  {
    "scenario": "closed",
    "repo": "openclaw/clawhub",
    "before": {
      "exit": 0,
      "requests": 1,
      "stdout": "{\"status\":\"superseded\",\"reason\":\"item_not_open\",\"state\":\"closed\"}",
      "errorClass": null
    },
    "after": {
      "exit": 0,
      "requests": 1,
      "stdout": "{\"status\":\"superseded\",\"reason\":\"item_not_open\",\"state\":\"closed\"}",
      "errorClass": null
    },
    "requestTraceIdentical": true
  },
  {
    "scenario": "transient",
    "repo": "openclaw/openclaw",
    "before": {
      "exit": 0,
      "requests": 2,
      "stdout": "{\"status\":\"superseded\",\"reason\":\"item_not_open\",\"state\":\"closed\"}",
      "errorClass": null
    },
    "after": {
      "exit": 0,
      "requests": 2,
      "stdout": "{\"status\":\"superseded\",\"reason\":\"item_not_open\",\"state\":\"closed\"}",
      "errorClass": null
    },
    "requestTraceIdentical": true
  },
  {
    "scenario": "transient",
    "repo": "openclaw/clawhub",
    "before": {
      "exit": 0,
      "requests": 2,
      "stdout": "{\"status\":\"superseded\",\"reason\":\"item_not_open\",\"state\":\"closed\"}",
      "errorClass": null
    },
    "after": {
      "exit": 0,
      "requests": 2,
      "stdout": "{\"status\":\"superseded\",\"reason\":\"item_not_open\",\"state\":\"closed\"}",
      "errorClass": null
    },
    "requestTraceIdentical": true
  },
  {
    "scenario": "malformed",
    "repo": "openclaw/openclaw",
    "before": {
      "exit": 0,
      "requests": 2,
      "stdout": "{\"status\":\"superseded\",\"reason\":\"item_not_open\",\"state\":\"closed\"}",
      "errorClass": null
    },
    "after": {
      "exit": 0,
      "requests": 2,
      "stdout": "{\"status\":\"superseded\",\"reason\":\"item_not_open\",\"state\":\"closed\"}",
      "errorClass": null
    },
    "requestTraceIdentical": true
  },
  {
    "scenario": "malformed",
    "repo": "openclaw/clawhub",
    "before": {
      "exit": 0,
      "requests": 2,
      "stdout": "{\"status\":\"superseded\",\"reason\":\"item_not_open\",\"state\":\"closed\"}",
      "errorClass": null
    },
    "after": {
      "exit": 0,
      "requests": 2,
      "stdout": "{\"status\":\"superseded\",\"reason\":\"item_not_open\",\"state\":\"closed\"}",
      "errorClass": null
    },
    "requestTraceIdentical": true
  },
  {
    "scenario": "throttle",
    "repo": "openclaw/openclaw",
    "before": {
      "exit": 1,
      "requests": 1,
      "stdout": "",
      "errorClass": "GitHubRateLimitError"
    },
    "after": {
      "exit": 1,
      "requests": 1,
      "stdout": "",
      "errorClass": "GitHubRateLimitError"
    },
    "requestTraceIdentical": true
  },
  {
    "scenario": "throttle",
    "repo": "openclaw/clawhub",
    "before": {
      "exit": 1,
      "requests": 1,
      "stdout": "",
      "errorClass": "GitHubRateLimitError"
    },
    "after": {
      "exit": 1,
      "requests": 1,
      "stdout": "",
      "errorClass": "GitHubRateLimitError"
    },
    "requestTraceIdentical": true
  }
]

Every trace uses only the synthetic row3-fixture-not-a-secret credential and api repos/<target>/issues/42, including the repeated retry attempts. Artifacts and executable driver: ~/Developer/.agents/handoffs/clawsweeper-row3/slice4a-revision-proof-replay/ and github-cli-revision-proof.mjs.

Validation and limits

  • Native macOS arm64, Node v24.21.0: build:all, 266/266 focused tests (including hydration, deadline, ETag, credential, egress, circuit, apply budget, action-ledger, close-reasons, and batch-workflow files), lint, and format:check: pueue 1637 passed.
  • codex review --base origin/main: the historical-driver finding from 1637 was fixed; fresh review 1644 and exact committed-head review 1646 found no actionable defects.
  • Linux Docker node:24.21.0-bookworm, network disabled: old hydration baseline at 16505cf and current candidate passed in 1644; exact current head passed again in 1646. Receipts: hydration-1898-history-baseline/, hydration-1898-history-candidate/, hydration-1898-head/ under the same handoff directory.
  • Prior eight-publisher quota-loopback and all 23 deadline scenarios remain covered; this revision does not change production behavior.
  • Not the full test suite. The CLI comparison covers closed-item reservation, not lease creation or a deployed Worker. Controlled local transports do not establish production throughput or quota accounting. No live credentials or GitHub mutations were used.
  • No stored schema, report-reading/retention, or Bay contract changes; no Bay change or 80k report-memory proof is needed. The typed reader cutover is preserved. Slice 5 remains outside this PR because its automation/publication owners overlap the separate typed-reader work.

No merge or deployment is requested.

@clawsweeper

clawsweeper Bot commented Oct 10, 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 P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. 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. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR replaces the GitHub runtime factory with direct operations and command-scoped budgets, credential reservations, and retained ETag responses.

Example: An asynchronous command resumes inside a 20,000 ms runtime budget.

  • Before: The synchronous budget wrapper restores its previous state before the continuation resumes, leaving the continuation unbudgeted.
  • After: The continuation retains its budget, while a separate command remains unbudgeted.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent, supported cutover with the previous blocker fixed; controlled transport evidence establishes the scoped behavior without claiming production performance.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Supplied actual CLI terminal traces exercise routing, JSON parsing, retries, and throttling through the migrated runtime on macOS Node 24; baseline isolation failures and current-head Linux cancellation results support the changed state lifetime and revised proof driver, without claiming deployed Worker or production throughput coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: GitHub budgets and retained responses can escape their intended command lifetime when commands share a process or resume asynchronously.
Reason: The maintainer-authorized direction removes factory wiring and fixes demonstrated state isolation without adding configuration or expanding the public contract.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: the command-state refactor is useful, the prior P2 is resolved, and inspection found no new actionable defect.

Priority: P3
Reviewed head: 6f8ca6631af750e9fbac3c7b2f9782778743e510

Before merge

None.

Findings

None.

Agent review details

How this fits together

The CLI wraps command dispatch in a GitHub data scope; runtime operations consume request arguments, credentials, and deadlines and return responses or typed failures through the existing transport.

flowchart TD
  A[CLI command] --> B[Command data scope]
  B --> C[GitHub execution]
  C --> D[Runtime operations]
  B --> D
  D --> E[GitHub transport]
  D --> F[ETag broker]
  E --> G[Response or typed error]
Loading

Technical review

Best possible solution:

Retain this focused command-state cutover and handle the dependent execution/context simplification separately.

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

Main's synchronous try/finally budget wrapper loses the scoped budget after an async callback returns its promise; the supplied baseline output also shows both new isolation scenarios failing before this change.

Is this the best way to solve the issue?

AsyncLocalStorage holds only command data, removes the previous factory owner, and preserves existing request classification, transport, retries, and durable broker contracts.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Runtime factory and command wiring changes intended behavior with a stated reason (4b5246a: The earlier runtime extraction simplified the launcher and separated cohesive owners while preserving conservative mutation guards.)
  • Deadline budgets and credential reservations keeps the original intent (74e5e42: Bound hydration metadata work by its absolute deadline and retain one-shot reservations after dispatch; this PR preserves those rules while changing data lifetime.)
  • Retained ETag responses keeps the original intent (c1a83a0: Avoid repeated broker round trips while requiring live conditional GitHub reads; retained bodies now have an explicit command lifetime.)
  • Concurrent first attempts keeps the original intent (fb5a0d9: Run independent reads concurrently while keeping existing retry, deadline, credential, and accounting behavior.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Command ownership: withGitHubRun creates fresh command data, and nested budget scopes share the command's sets and retained responses while replacing only the budget. (src/clawsweeper-github-runtime.ts:65, 6f8ca6631af7)
  • Shipped entry point: main wraps dispatch and action-event finalization in the command scope; direct transport calls retain the previous working directory, buffer, stdio, trimming, and timeout behavior. (src/clawsweeper-runtime.ts:1132, 6f8ca6631af7)
  • Prior finding resolved: The hydration recorder now captures the normalized error name and admitted deadline; assertions retain child termination, no metadata response, no completed delay, no fetch, and missing-blob checks. (docs/proof/hydration-deadline/run-proof.mjs:459, 6f8ca6631af7)
  • Supplied behavior evidence: The inspected PR body supplies eight actual CLI before/after traces covering two repositories, successful reads, transient retries, malformed JSON retries, and terminal throttling, plus baseline failures for both new isolation tests and current-head Linux cancellation results; sourceRevision is e87cf13d1e86b785ecccd9df71e9b016e6fd9f2fc230c6d57cc6ea15bff1557a. (6f8ca6631af7)
  • History and limits: Current-main history identifies Peter Steinberger's runtime, deadline, credential-routing, and ETag work and Ayaan Zaidi's concurrent-read work; older-content searches encountered unavailable promisor blobs, so earlier introduction is not asserted. (src/clawsweeper-github-runtime.ts, c2753fb49e25)
  • Separate dependent work: refactor: import GitHub execution and context directly #1905 explicitly builds on this head and handles execution/context factory removal, rather than replacing this PR's runtime-state work.

Likely related people:

  • Peter Steinberger: Raw commit 74e5e42 adds src/clawsweeper-github-runtime.ts:60 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 74e5e42e80df; files: src/clawsweeper-github-runtime.ts)

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove merge-risk: 🚨 automation: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P3: This is a focused internal ownership refactor with isolation improvements and no demonstrated urgent production outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-10T13:50:26.044Z sha 69a050c :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T13:58:38.266Z sha 40f30d5 :: needs changes before merge. :: [P2] Align the hydration proof recorder with deadline normalization

Reviewed October 10, 2026, 11:18 AM ET / 15:18 UTC (Revision 3).

@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
@obviyus
obviyus force-pushed the cleanup/row3-github-runtime branch from 40f30d5 to 6f8ca66 Compare October 10, 2026 15:15
@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. 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. and removed merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 10, 2026
@obviyus
obviyus merged commit f58fc2d into main Oct 10, 2026
33 of 35 checks passed
@obviyus
obviyus deleted the cleanup/row3-github-runtime branch October 10, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. proof: sufficient Contributor real behavior proof is sufficient. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant