Repository navigation
refactor(sessions): run fork transactions in the agent executor (compound 3a) - #164891
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 9:43 AM ET / 13:43 UTC (Revision 7). ClawSweeper reviewWhat this changesMoves session-history forks and child-session updates into the existing agent database worker while preserving storage, callback, and source-session behavior. Merge readiness✅ Ready for maintainer review This refactor remains useful: pinned main still executes parent-fork transactions on the caller thread. No introduced correctness or security defect was found; the recorded CI failures remain subject to native landing gates. Priority: P2 Review scores
Verification
How this fits togetherSession forks copy existing conversation history into a child session. Gateway, reply, and voice callers feed the session storage owner, which commits the copied history and publishes the child’s identity. flowchart TD
A[Gateway and agent callers] --> B[Capture source and target stores]
B --> C[Prepare fork history]
C --> D[Agent database worker]
D --> E[Check current authority and rows]
E --> F[Commit child history]
F --> G[Publish acknowledged session identity]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +955, Tests +275, Docs +10, Other +1. Total +1241 across 23 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep fork persistence under the canonical agent executor, with live commit guards, acknowledged publication, and the existing native compatibility paths. Do we have a high-confidence way to reproduce the issue? Not applicable as a behavioral bug report; source inspection establishes the existing caller-thread fork transactions, and supplied runtime observations exercise their worker replacement. Is this the best way to solve the issue? Yes. Reusing the canonical executor, synchronous kernels, and receipt owner preserves one storage responsibility without introducing another writer or changing the released callback contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 086ad165b674. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
Fork transactions now run through the agent executor, so exercise their existing live-authority check at worker commit admission alongside rewind and branch switching. Preserve the unchanged-storage and denied-response assertions and remove the obsolete native writer-queue fixture branch. Five reproductions confirmed the old fork assertions fail; the full corrected storage suite passes all 30 tests. Production code is unchanged.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Add the fork domain to the existing exact-module inventory for the loader's required bindSqliteWorkerBackend entry point. Keep the protocol rule, unknown-module rejection, and runtime implementation unchanged. The complete collision scan and its 54 existing tests pass. Focused scans of the reported modules reproduced the omitted registration five times on the PR and no collision five times on its merge base.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…ound 3a) (openclaw#164891) * refactor(sessions): run fork transactions in the agent executor * test(gateway): revoke fork authority at worker commit admission Fork transactions now run through the agent executor, so exercise their existing live-authority check at worker commit admission alongside rewind and branch switching. Preserve the unchanged-storage and denied-response assertions and remove the obsolete native writer-queue fixture branch. Five reproductions confirmed the old fork assertions fail; the full corrected storage suite passes all 30 tests. Production code is unchanged. * fix(ci): register the session fork worker protocol export Add the fork domain to the existing exact-module inventory for the loader's required bindSqliteWorkerBackend entry point. Keep the protocol rule, unknown-module rejection, and runtime implementation unchanged. The complete collision scan and its 54 existing tests pass. Focused scans of the reported modules reproduced the omitted registration five times on the PR and no collision five times on its merge base.
What Problem This Solves
Parent transcript/child-entry forks and message-cut forks still ran their compound SQLite work on the caller thread. Cold target discovery also retained host SQL, and repository-backed forks reloaded the source session inside worker admission grants.
Why This Change Was Made
Run fork preparation and commits in the canonical agent executor through its existing connection-bound
database.domain.publishenvelope. Capture both physical stores before discovery yields, retain their owners, and reuse the synchronous transaction kernels and acknowledged-publication owner. Same-store forks remain atomic; cross-store forks retain the existing source-snapshot/target-commit behavior.Bundled fork/skip patches are typed data. Repository forks compare the captured source workspace against the transaction's fresh row, while host grants check published repository facts. Shared-store forks keep the logical agent separate from the physical owner. Cleanup failures cannot turn an acknowledged fork into an apparent failed write.
Builds on #163889, #163930, #164391, #164753, and #164197. Architectural overlap with @clawSean's #158030: reuse the executor direction while keeping the existing fork entry points; this PR does not add its fork command feature. Incidental overlap with #162433 remains limited to the touched owner paths.
User Impact
No user-visible contract change. Fork persistence moves off the Gateway caller thread while preserving source history and child-session behavior.
06d4475d6079aaa875a9b477ac0935d1459b1023. Shared native kernels remain counted for their retained contracts; the new bound transaction adapter is worker-owned.Codex behavior was checked in sibling
../codexatade0ccacf9182e665cf784de041c51a79e35bc31,codex-rs/app-server/src/request_processors/thread_processor.rs:1011: unsubscribe is connection-specific and distinguishes not-loaded/not-subscribed outcomes. Fork does not retire that source context.Preexisting other-owner read debt is retained:
src/gateway/server-methods/sessions-rewind.ts:547reads the agent source during shared-state repository preparation;:610reads the target during repository cleanup. The legacy/unprepared operator-role fallback atsrc/gateway/operator-role-policy.ts:48reads the shared profile owner. Prepared repository/profile authority checks consume published facts. Boundary assertions cover the moved operations, not those other-owner reads.Evidence
All local Vitest commands use
--maxWorkers=1; this host is heavily loaded. CI seconds are not yet measured.node scripts/check-changed.mjs --base 06d4475d6079aaa875a9b477ac0935d1459b1023OUTPUT_SOURCE_MAPS=1 pnpm build)sessions.forkwith exact prefix/source checksThe synthetic Gateway workload verified the exact 20-message fork prefix, unchanged source, successful subagent completion, mentions, cron, compaction, and exit code 0. Its broader fork phase (including source/child history validation) recorded 25 caller-thread statements and 600 worker-thread statements, with no fork SQL errors. Existing admission/lookup reads outside the moved transaction remain; the targeted boundary tests establish 37 -> 0 for the moved same-store and cross-store paths. This is correctness and SQL-location evidence, not a matched-baseline latency claim.
Harness caveat: two transient audit-prune lock attempts recovered during shutdown; the subsequent audit DELETE/COMMIT succeeded. The activity-summary notification abort is independently reproduced on unchanged main
f8f1c8af73a7b874db7c2693345e41a8a6033713and this PR head through the same real synthetic Gateway workload (41 successful RPCs, exact fork prefix, unchanged source, successful compaction, clean shutdown). Passive abort stacks identifydirect-compaction.ts:76: compaction closes its ambient work scope while the asynchronous activity-summary publisher is still preparing rows. The warning precedes the compact response and Gateway shutdown, so this is not CLOSE-PRELUDE or an accepted fork write loss. All nine relevant compaction/publisher/scheduler/scope owners are byte-identical on the PR, merge base, and main. On main, no current recap push arrived during 111.5 seconds of observation; the normal scheduled refresh also aborted its push when the scheduler scope drained. A read-only query after shutdown confirmed a fresh persisted recap covering 22/22 messages at the current transcript generation and max sequence 36. This is an inherited notification-publication gap; redelivery is not claimed. Follow-up belongs to the activity-summary publication owner, which currently inherits the triggering task cancellation scope despite Gateway-owned Promise tracking.The full check-changed run preceded the final test-only error-class assertion; that assertion passed its focused test, lint, and messaging typecheck. Production source remained unchanged.
The three shared-store/cleanup regressions failed for their intended reasons before repair and passed afterward. The repository grant regression caught ten same-owner row reads before repair; its workspace race confirms refusal and prepared-child cleanup.
Released SDK surface rechecked against latest local release
v2026.9.8(fc23bc864e4553c2d215e479eeec47b67a0bf943): the changed bundledforkSessionEntryFromParentcallback shape is internal-only (no SDK/runtime export); the public accessor callback contract and result unions remain unchanged. No released signature removal or sync/async change requires a compatibility record. Local native SDK comparison: no entrypoint/exported-signature/add/remove changes. Complete public executable command maps, execution scope, message-cut inputs, registered commit signature, and existing result unions are byte-identical to the base. The 127 reachable-only changes are internal helpers/types; acknowledgement digest 45c0e757. Baseline render: 756.54 s; candidate render: 1,161.58 s. Subsequent edits only strengthen test observation; production declaration inputs are unchanged.Focused test commands and wall times
Landing investigation and correction
The first CI attempt (
37199330010) failed the two fork authority cases insessions-rewind.storage.test.ts. Five full-file merge-base runs passed all 29 original tests. Five local PR-head reproductions (one complete file run and four focused single-file runs, each--maxWorkers=1) confirmed the same obsolete fixture assumption: forks were still revoked through the native writer queue even though their transaction now runs in the worker. The correction uses the existing worker commit-admission interception for fork, rewind, and branch switch, preserving the exact denied error and unchanged persisted state assertions.node scripts/run-vitest.mjs src/gateway/server-methods/sessions-rewind.storage.test.ts --maxWorkers=1now passes all 30 tests (144.52 seconds runner wall time). The initial CI shard spent 87.45 seconds across 23 files; the corrected head's CI timing will be recorded after completion. The scoped changed-check pipeline also passed, including Gateway test types, lint, formatting, and repository guards. Production source is unchanged by this correction. A fresh isolated P2 autoreview of the correction is scoped-clean; the original full production review remains valid.The same attempt also failed
run.plugin-runtime-refresh.integration.test.ts(workspace consumer assertion during warmup) andrun.session-permissions.test.ts(Agent admission requires its host owner). Both failures independently reproduce on plain mainee535071298162d378fafa53f696ad1fb36b3263, in the original three-file shard order (110.83 seconds) and individually. Main'se95e11c679301368a2f30f09e13647597c65f730moved run admission toreadSessionEntryInWorker, while those fixtures remain in the thread pool rather than the existing host-owned database-worker fixture. The unchanged host-owner check fails before worker command dispatch or fork execution; the workspace assertion masks that earlier warmup exception. All 17 causal source inputs are identical between CI's main parent and tested merge. Both failing embedded files also pass five standalone runs each on the raw PR and five each on the merge base; their original selected shard passes 62/62 on both. These inherited failures use the explicitly authorized native admin evidence route if they remain on the corrected head.The corrected head's CI attempt (
37200787188) found the newsession-fork-domain.worker.tsmissing from the existing exact-module inventory for the loader-requiredbindSqliteWorkerBackendexport. The follow-up registers this module under the unchanged protocol rule; unknown modules and other duplicate names remain rejected. The full scanner reproduced the one collision, and five focused canonical guard evaluations over every reported module found one collision on the PR versus none on its merge base. The corrected full scanner passes; its 54 existing tests pass in 10.04 seconds, with formatting, lint, line-growth guards, and a fresh P2 review also passing. Runtime code and public SDK declarations remain unchanged.That attempt also exposed two
sessions.dispatch.demand.test.tsfailures (spreads later Auto work while a completed dispatch awaits physical slot publicationanddoes not reserve capacity for a retained placement after admission is released). Both independently reproduce on plain mainb2b434acbc624ed0c212fa2941dc9ac1fa5f1731: the fixture'sgetMany-only placement service lacksprepareRuntimeRefresh, required by main's placement-reader change. The first explicit send is refused before dispatch or fork execution. This second inherited fixture regression is also covered by the authorized admin route if still present.The PR context check initially rejected the old
Problemheading; changing it to the current template heading repaired the metadata check (workflow37200915454passed).Final-head CI
37201627004, attempt 1, testededbdc8b0fbc4806ee6bc874bdc5b37cf77ff4f87in merge checkoute21d765f9552c71d302ee4658751cae6ffef39fdwith main parentd9f36acbe3b6c8a29ddeffe1e89ebe2b6992d085: 93 jobs passed, 20 skipped, five root jobs failed, and the aggregate failed; no jobs were cancelled. The repaired fork authority fixture and worker-protocol inventory checks passed. This run is not represented as green.Four root jobs are independently inherited. In addition to the two warmup suites and two placement-demand cases above,
run.prepared-harness-credentials.test.ts(three cases),run.recovery-deadline.test.ts(warmup),run.terminal-timeout-delivery.integration.test.ts(warmup), andrun.inherited-auth-owner.test.ts(one case) hit the same main-only host-admission routing defect. Every additional failure reproduces on the exact CI main parent in the observed shard order. Each of those four files also passed five standalone runs on the raw PR and five on its merge base (40 invocations, 100 test executions total, all--maxWorkers=1). Scheduled main CI37200643847independently records the same six embedded-file failures in jobs111431627089,111431627124, and111431627123. The 30 combined causal source paths for all four root jobs are byte-identical between the tested merge and its main parent. The native exception retains those failed results and their independently inspected evidence.The UI root (
worker-initial-setup.real-gateway.e2e.test.ts, job111434536638) remains unattributed after the required investigation. CI expected two launches but observed one after the tool run reportedSession setup-proof-session placement authority changed. Five standalone raw-PR runs and five merge-base runs all passed with--maxWorkers=1; five additional Linux replays of the exact main source tree also passed. The latter used a repository-owned Blacksmith Testbox (run 37204694865), verified source treeecac9702d1a8327422392250bef6e2d0e96dd87bfrom maind9f36ac, built normally, completed the command with exit 0 in 394.29 seconds, and stopped its lease. Exact-parent main also passed the target standalone and in the original 14-file shard on macOS; that shard had a separate chat-stop failure, recorded independently.The unchanged placement observer can be invalidated by an overlapping turn's ACK/result publication. Main #164744 introduced asynchronous placement preparation before turn execution; CI logged the tool's rejection about 84 ms after one fixture launch reached its transcript append. However, the log lacks the throwing preparation callsite, publication kind, and launched run ID, so that interleaving is a hypothesis. The shared agent-publication helper remains reachable but submits the same command synchronously without adding an asynchronous boundary, and the scenario does not request a fork. No applicable main fix was found through
82adb7a. Neither inheritance nor a PR-caused defect is claimed for this root. Under the operator's explicit unresolved-failure policy, exactly one rerun of this UI job was submitted on unchanged source after the bounded comparisons. It passed as job111445612309in attempt 2 (604 seconds job wall time). This is not a code fix; the original failure and uncertainty remain recorded. Final attempt 2 has 94 successful jobs, 20 skips, four inherited Node roots, and the failed aggregate, with no cancellations. GitHub carried forward the four Node results into new job IDs; their names, conclusions, original start/completion times, and complete steps exactly match attempt 1. Native admin admission binds those copied results to the original inspected logs and independent main reproductions. The exact-head ClawSweeper review completed with no findings or security concerns.