Skip to content

refactor(projects): move session project resolution to shared worker - #150249

Merged
steipete merged 91 commits into
mainfrom
codex/projects-activation-main8f8-20260916
Sep 18, 2026
Merged

steipete merged 91 commits into
mainfrom
codex/projects-activation-main8f8-20260916

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Project-backed session creation, reset, title generation, and explicit Doctor workspace repair still resolve registered Projects data on their caller threads.

User Impact

These reads use the shared database worker while preserving cancellation, stale-source refusal, session commit ownership, and worktree recovery. Explicit Doctor repair remains the only writer of missing workspace metadata; startup continues to detect it. No schema or configuration change is required.

A reset that commits before its source scope fails during cleanup now still performs its scheduled ACP preparation and reset hook. It reports the original cleanup error and preserves both errors if the post-commit action also fails, without rolling back the committed session.

Why This Change Was Made

The Projects owner provides finite source scopes around workspace effects and final session commits. Title generation and setup settlement remain outside checkout custody, while each effect rechecks current authority. Restoration cleanup requires a fresh recovery snapshot before deleting restored data.

The current carry integrates main 4c2cf51e120484977831ecd89960bcfce1b8255d to resolve substantive conflicts with its title-state and ACP reset owners. It retains the shared pending-title registry and canonical-key ACP metadata binding. A newly expanded worktree caller now imports explicit-title selection from the canonical session-title-state module. The existing lifecycle-preparation module now owns settlement of recorded commit actions, including preservation of source and post-commit failures.

Native SQL remains in checkout leases, checkout-reference removal, and legacy agent/worktree migration reads. Checkout-reference deletion is not fully fenced; this change does not eliminate every caller-thread SQLite operation.

Evidence

The final 34-file source passed all 31 selected static checks and fresh independent P2 review with no actionable findings. The normal build passed in 7m 41.3s, including built-module and Doctor dependency validation. The title suite passed 60 cases after its canonical worker compiler reproduced the stale-import failure. The registered Doctor repair passed, and eight worktree-spawn cases passed, including stale-parent rejection and rollback. The new reset-service regression failed with the durable commit present but deferred actions absent; the final structure passed all ten reset cases, including a second post-commit failure. Earlier failures remain retained, and no assertion, timeout, or baseline was weakened.

The earlier candidate d40b62935ac16595fd199644f0a66916ef86fa7a passed a normal build, package integrity checks, and all 29 phases of the published 2026.9.4 updater cell with tarball SHA256 870f8907e6bbb4b75268736eae3557ab90fb74840565eb9a11f4df821802b4d7. All 9,871 installed application entries matched. Doctor repaired workspace metadata before Gateway startup, and both subsequent starts preserved it without backfilling. Those results and the earlier db3194e07ccc12409327296195f95d222456903f measurements remain attributed to their original source and artifacts; they are not new updater proof for this carry. Simulated Windows controls are not real Windows execution.

The prior public-head CI run remains failed, with retained source attribution for its UI budget, Slack lint, skill-read, and tooling-fixture failures. No unchanged-head CI retry or native fault campaign was run here.

Related: #150010, #150055.

Preserve the reviewed removal change while inheriting the canonical wrapper fixture correction and current main ownership. This is a private source composition; prior timeout causes remain unattributed and qualification is still pending.
steipete and others added 6 commits September 17, 2026 22:45
Preserve trailing string whitespace and recover raw-newline output through
one decoder that retains fragments instead of repeatedly parsing each
growing prefix. Keep native JSON validation, synchronous FIFO delivery,
the existing recovery limits, and redacted diagnostics.

Validated client and transport regressions, selected source checks,
independent review, and an eight-arm matched component replay.
…151417)

Remove duplicate child-roster setup introduced by the clean textual composition of #147568 and #148447. Restore the exact previously landed browser-budget fixture while retaining committed-roster polling, scroll-idle synchronization, all six cases, and every assertion and budget.

Validate current source files before measuring historical line-count debt. Only currently over-cap files need that allowance, so valid under-cap syntax repairs are no longer blocked by a malformed old file. Invalid current files and unmeasurable over-cap baselines still fail closed; no caps, baselines or suppression rules change.

Co-authored-by: steipete <[email protected]>
…51377)

## What Problem This Solves
Fixes repeated retries of deterministic HTTP 402 budget rejections when the billing help URL contains an organization or workspace keyword.

## User Impact
Budget failures reach normal billing handling without spending the transient retry budget. Genuine HTTP 429 recovery is unchanged.

## Why This Change Was Made
The shared 402 classifier combined a scope word from a URL with “limit exceeded” from the error text. Exclude HTTP(S) URLs from classification text only; preserve raw errors. This adds no state writer.

## Evidence
The shipped `pnpm openclaw agent exec` command now completes the full transport → normalization → recovery → final-result flow against a synthetic local provider, without mocked runtime callbacks.

| Case | HTTP requests | Retry decisions | Final result |
| --- | ---: | ---: | --- |
| Baseline prompt-budget 402 | 2 | 2 | Cancelled after reproduction; billing invariant fails |
| Fixed prompt-budget 402 | 1 | 0 | Billing error |
| Fixed output-budget 402 | 1 | 0 | Billing error |
| Fixed temporary 429 → 200 | 2 | 1 | `SYNTHETIC_RECOVERY_OK` |

832 focused tests passed; the final fixture cleanup passed all 91 affected tests. Native types, lint, and generated protocol checks pass. No paid request was made.

<details>
<summary>Captured complete agent-command proof</summary>

Candidate `e20c5f257727`; baseline `8d6decdecafe`. The three candidate command scenarios were rerun after refreshing main to include the merged CI policy repair; all results below remain unchanged. The PR's changed lines are byte-identical across that refresh. Each command uses isolated state, an empty workspace, synthetic credentials and a local HTTP endpoint configured through the supported provider settings. No tools or fallbacks are enabled.

```bash
pnpm --silent openclaw agent exec 'Reply with the synthetic provider response. Do not use tools.' --config '<synthetic-config>' --state-dir '<isolated-state>' --cwd '<empty-workspace>' --model openrouter/example/model --thinking off --code-mode direct --timeout 90 --json
```

Baseline diagnostic excerpts, stopped after the second identical 402 response:

```text
transient same-model retry 1/9 for openrouter/example/model reason=rate_limit: delayMs=992
transient same-model retry 2/9 for openrouter/example/model reason=rate_limit: delayMs=1034
```

The baseline command exits 130 from intentional cancellation before a third request. The same offline invariant check exits 1 for baseline and 0 for both candidate billing cases.

Candidate billing result excerpt (both 402 shapes; CLI exit 1 is the expected final error):

```json
{
  "ok": false,
  "status": "error",
  "final": "",
  "payloads": [],
  "error": {
    "message": "⚠️ openrouter (example/model) returned a billing error — your API key has run out of credits or has an insufficient balance. Check your openrouter billing dashboard and top up or switch to a different API key.",
    "kind": "exception"
  }
}
```

Temporary 429 then valid streamed 200 response (CLI exit 0):

```text
transient same-model retry 1/9 for openrouter/example/model reason=rate_limit: delayMs=1041
```

```json
{"ok":true,"status":"ok","final":"SYNTHETIC_RECOVERY_OK","assistantTurns":2}
```

Result excerpts omit generated session identifiers and unrelated metadata. Provider captures confirm one request per candidate billing case and two for 429 recovery. The real retry delay runs; no sleep mock is used. The baseline and candidate receive byte-identical prompt-budget response bodies. All six provider requests are synthetic and local.

</details>

<details>
<summary>Captured transport-backed regression output</summary>

Synthetic response: HTTP 402 with `{ "error": { "code": 402, "message": "Prompt tokens limit exceeded: 24338 > 16443. To increase, visit https://example.invalid/organizations/synthetic/settings/keys and adjust the key's total limit" } }`.

Before: unchanged production at `8d6decdecafe`, using the added fixture:

```text
node node_modules/vitest/vitest.mjs run --config test/vitest/vitest.tooling.config.ts test/plugins/openrouter-error-classification.integration.test.ts

× does not retry an HTTP 402 key budget rejection: Prompt tokens limit exceeded: 24338 > 16443. To increase, visit https://example.invalid/organizations/synthetic/settings/keys and adjust the key's total limit
→ expected 'rate_limit' to be 'billing'
→ expected { action: 'retry', …(4) } to deeply equal { action: 'proceed' }
→ expected 1 to be +0
Tests  1 failed | 8 passed (9)
exit 1
```

After: `e717ea160060`, through the supported test runner:

```text
node scripts/run-vitest.mjs run src/agents/embedded-agent-runner/run/attempt-recovery.test.ts src/agents/embedded-agent-runner/run/attempt-recovery.per-day-rate-limit.test.ts test/plugins/openrouter-error-classification.integration.test.ts

✓ does not retry an HTTP 402 key budget rejection: Prompt tokens limit exceeded: 24338 > 16443. To increase, visit https://example.invalid/organizations/synthetic/settings/keys and adjust the key's total limit
✓ does not retry an HTTP 402 key budget rejection: This request requires more credits, or fewer max_tokens. You requested up to 2048 tokens, but can only afford 1954. To increase, visit https://example.invalid/organizations/synthetic/settings/keys and adjust the key's total limit
✓ keeps genuine HTTP 429 recovery at nine same-model retries
Tests  9 passed (9)
Tests  82 passed (82)
exit 0
```

These are captured output excerpts; test prefixes and timing columns were removed. The passing 402 assertions verify one HTTP request, preserved error status/body, `billing`, `proceed`, and zero retry events, sleeps or transcript continuations. The 429 control verifies nine recovery decisions from one real HTTP response, not nine network requests. All endpoints and account-path components are synthetic.

</details>

## Compatibility
No configuration, schema, protocol, or retry-budget changes.

## Consumers
Existing shared failover callers receive the corrected reason.

## Invalidation
No cache or stored state changes.

## Tests
Regression command: `node scripts/run-vitest.mjs run test/plugins/openrouter-error-classification.integration.test.ts`. Synthetic HTTP proof; no new live-provider run.

Co-authored-by: Ayaan Zaidi <[email protected]>
@steipete
steipete marked this pull request as draft September 18, 2026 07:33
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: matrix Channel integration: matrix app: android App: android app: web-ui App: web-ui cli CLI command changes scripts Repository scripts commands Command implementations extensions: qa-lab extensions: codex plugin: workboard extensions: active-memory labels Sep 18, 2026
@steipete
steipete marked this pull request as ready for review September 18, 2026 08:30
@steipete
steipete requested a review from a team as a code owner September 18, 2026 08:30
@steipete
steipete merged commit cfec084 into main Sep 18, 2026
438 of 440 checks passed
@steipete
steipete deleted the codex/projects-activation-main8f8-20260916 branch September 18, 2026 13:19
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 18, 2026
Settle required reset notifications, watcher cleanup, lifecycle hooks, unbinding, and worktree cleanup after durable commit even when source release or ACP preparation fails. Preserve the original errors and record actions before fallible commit callbacks.

Refs #150249. Regression proof: four failure cases fail before the repair; 255 focused tests and changed checks pass afterward.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 19, 2026
…penclaw#150249)

Move stored project resolution onto the shared SQLite worker and retain captured project authority through worktree setup, session publication, and rollback. Keep title generation and ACP reset preparation with their existing lifecycle owners.

After a session reset commits, join deferred post-commit actions even if source-scope cleanup fails. Preserve both errors when cleanup and post-commit work fail, without rolling back the committed session.

Validation: 31 selected checks, normal build, title and worktree lifecycle controls, registered Doctor proof, and 10 reset regression cases passed. Exact-head CI passed after one targeted rerun on the same merge tree; the original Anthropic timeout remains unexplained, with its deadline and assertions unchanged.

Native checkout lease and remaining session migration/cleanup SQL remain separate follow-up work.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 19, 2026
…aw#151955)

Settle required reset notifications, watcher cleanup, lifecycle hooks, unbinding, and worktree cleanup after durable commit even when source release or ACP preparation fails. Preserve the original errors and record actions before fallible commit callbacks.

Refs openclaw#150249. Regression proof: four failure cases fail before the repair; 255 focused tests and changed checks pass afterward.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: android App: android app: web-ui App: web-ui channel: matrix Channel integration: matrix cli CLI command changes commands Command implementations docs Improvements or additions to documentation extensions: active-memory extensions: codex extensions: qa-lab gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. plugin: workboard rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL 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.

7 participants