Repository navigation
fix(sessions): check caller authority before restoring cold history for compaction - #166506
Conversation
Carry prepared caller/source authority and captured session lifecycle through cold-history restoration, and revalidate them before writes and commit. Preserve native SDK commit guards and reader/writer ordering. Reuse entry-reader preflight facts and isolate shared source predicates from write-owner imports. Denied or rebound requests leave cold history unchanged.
|
🦞👀 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. |
|
|
Codex review: needs changes before merge. Reviewed October 7, 2026, 8:50 AM ET / 12:50 UTC (Revision 8). ClawSweeper reviewWhat this changesThe PR carries caller authority, session lifecycle, and physical storage identity through manual compaction so revoked or rebound requests cannot commit restored history. Merge readiness⛔ Needs changes before merge - 1 item remains This remains a necessary repair: current main still restores cold history without carrying the compaction caller’s authority into restoration. No introduced correctness or security defect was found, and the previous worker-abort investigation request is satisfied. Priority: P2 Review scores
Verification
How this fits togetherManual session compaction receives a Gateway request and trims stored conversation history. Archived history must first be restored through the SQLite worker, where authorization must remain current before restoration commits. flowchart TD
A[Compaction request] --> B[Caller and session authority]
B --> C[Selected physical store]
C --> D[Cold history restoration worker]
D --> E{Authority still current}
E -->|Yes| F[Commit restoration and trim history]
E -->|No| G[Rollback and report refusal]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +506, Tests +442, Docs +18. Total +966 across 30 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep restoration and trimming under their existing storage owners, with live caller checks and transaction-local source predicates preserving authorized behavior and rejecting stale requests. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the unguarded current-main restoration path, and the contributor records a failing baseline regression. This read-only review did not execute it. Is this the best way to solve the issue? Yes, the patch extends the existing restoration owner’s authority checks and retains native SDK fences rather than adding a competing writer or authorization owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ccadf6ace875. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (7 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…#166506) Carry prepared caller/source authority and captured session lifecycle through cold-history restoration, and revalidate them before writes and commit. Preserve native SDK commit guards and reader/writer ordering. Reuse entry-reader preflight facts and isolate shared source predicates from write-owner imports. Denied or rebound requests leave cold history unchanged.
What Problem This Solves
sessions.compactwithmaxLinescould restore cold transcript rows after its caller lost authority or its session lifecycle changed during preparation or queue waits. Entry-time authorization did not protect restoration's earlier write.Solution
Carry the selected physical store, prepared caller/sharing authority, session ID, and lifecycle through the trim facade. The existing entry reader prepares target/source facts and cold metadata together. The restoration worker validates typed source and lifecycle predicates before writing and at commit; the host checks live caller authority across waits. Foreign durable sources receive fresh final checks, including when a source initially aliases the target. Refusal rolls back restoration.
Prepared checks survive composition with opaque SDK callbacks. Those callbacks keep their released synchronous native fences. Native trimming retains FIFO ordering, atomic transcript/entry updates, and full final assertions. The shared predicate reader has one leaf implementation used by all seven consumers.
Impact
Denied requests leave hot rows and archive metadata unchanged. Authorized compaction retains its existing behavior. No schema, stored-format, retention, durability, protocol, configuration, update, or accepted-work settlement change; zero new
OPENCLAW_*names or caller-thread SQL sites. FullmaxLinesworker writing remains follow-up work because native trim preserves released synchronous SDK contracts.The current product delta contains 30 files, including two docs and two test files. The lifecycle-policy and predicate-reader extractions retain one implementation each. The unchanged introduced delta adds no caller-thread SQL sites; the worker ratchet shows no growth.
Retained host-read follow-up:
src/gateway/server-methods/session-mutation-guards.ts:428rechecks the current operator role. When prepared profile/run authority is unavailable and the existing role cache misses,src/gateway/operator-role-policy.ts:48callsgetUserProfileRole(src/state/user-profiles.ts:129), which performs an indexed shared-state profile lookup (src/state/user-profiles-internal.ts:231). This unchanged other-owner fallback keeps revocation live; it is outside the agent database being restored. Normal prepared profile/run checks consume owner-held facts. No new SQL site is added, and no test requires every possible host grant callback to execute zero SQL.Overlap: #166293 moves transcript reads to the retained history owner and leaves this
maxLinesrepair. Main's #166365 moves generic cold metadata to the projection lane and is included. Session authority/creation and worker lifecycle fixes from main were integrated with merge commits, preserving their semantics.Evidence
The original denial regression fails on baseline
367d33f6dfae7e3d148cd0c2660d40901f75807f: the facade returns successful compaction instead of refusing (352.56s wall). The alias-rebinding regression also failed before its correction (179.36s). Coverage includes preparation, admission and commit revocation; lifecycle rebinding; foreign-source rollback; authorized restoration; opaque SDK composition; and Incognito behavior.Initial source validation passed the changed-check gate, package/tarball build checks, published
2026.9.8driver update, and Linux shutdown proof. The update preserved durable history, cleared Incognito history after restart, and reached readiness with the candidate build. The first main integration (aa06b5149774, main56bd0430d532) passed 192 tests across 12 files in 620.78s, all selected type lanes, and madge with zero cycles.The second integration is
854d185316b584330d15ef8024de272b669c8b15, containing main892911ba4f35f5bc05b50d798694780b3e5dc777. Its only conflict was additive storage documentation; both sides were retained. Fresh isolated P2 autoreview is scoped-clean.aa8ad4cd; 2015.77s including canonical cleanupAll focused invocations use
pnpm test <files> --maxWorkers=1. The build-graph and import-closure files executed in the combined run passed. Indirect callers already have their required host-owned routes. The new modules do not add a missing dependency to the compiled PR wrapper inventory.The latest integration is
b4d52b9ea7a7b247f6d366569d5744a64e4eab31, merging mainf2c5ed82c5f1066b4716c30de790cbe056ce7098. It includes the landed terminal-font type fixture fix (1d10375ee563b) and archive/category fixture cleanup (4ed39a25f674c), plus current main context. Both integrations were conflict-free. All 30 compactauth files are byte-identical to the preceding reviewed candidate. Fresh P2 autoreview is scoped-clean. Final-head validation is complete; the preceding table remains explicitly prior-head evidence.b4d52b9epnpm test <files> --maxWorkers=1CI run 37622654506 has one failing Node root, job 112797280980: the four independently reproduced continuation cases. The downstream aggregate failed; 52 jobs succeeded, 23 skipped, and 36 were cancelled by fail-fast. No cancelled job has a hidden failed step. The tested merge
ea30aca1b35ee3e89f24433afb0cb709c5603018has ordered parents main5a138f13and the PR head; its tree equals a fresh Git merge of those exact parents. Cancelled coverage and unavailable per-case CI timings are not claimed as passing proof. Landing uses the explicitly authorized native inherited-failure exception, subject to its live review/security/authority checks.Released SDK boundary
Compared the changed contracts against
v2026.10.1-beta.1,v2026.9.8, andv2026.9.7. Released signatures and exports remain compatible. The transcript assertion composer retains its released signature; the added compaction/worker parameters are internal. No compatibility adapter, deprecation record, or compatibility type test is required. The canonical SDK report for6d03a264passed in 366.94s with the identicalaa8ad4cddigest. Its original head binding is preserved. An explicit final-head API-equivalence audit confirms the 30 PR files are unchanged; the five imported main paths do not change the exposed SDK surface, inventories, dependencies, or toolchain. This is reused API proof, not a claim that the entire production tree is identical.SQL statement budget
The unchanged observer counts every successful native SQL execution across MAIN, workers, and child processes, including transactions, PRAGMAs, admission/schema checks, and background work. It excludes no successful SQL records. Both revisions pass the same seven-execution MAIN/worker calibration; SQL failures are recorded separately. These are real isolated Gateway RPCs, with pinned source and rebuilt artifacts.
The second integration's cold raw ALL total grew by 34. Unchanged periodic WAL calls grew by 36; subtracting only those independently traced timer calls gives an explanatory remainder of 2750 → 2748. This does not establish raw cold no-growth, and one remainder window still rises by 16. All raw results remain part of the evidence. Host load stretched the candidate fixture from 150.9s to 251.7s. A preregistered quiet-host ABBA comparison then completed all 24 requests unchanged: six cold requests per revision measured MAIN 378 → 372, ALL 5501 → 5366; six hot requests measured MAIN 378 → 372, ALL 1285 → 1113. Both paired comparisons and every corresponding raw window decreased. No records were filtered and no outcome-based extra samples were taken. These results bind the second integration; the required final-integration comparison is complete against
f2c5ed82:All 24 requests, calibrations, and shutdowns passed. Both paired contrasts and every corresponding raw window decreased. There were zero new MAIN sites and zero failed SQL statements/prepares. The same observer, fixture, timers, and fixed ABBA protocol retained every raw record; no outcome-based extra samples were taken. Both sources were built before measurements on one quiet isolated host. This supports measured no-growth for the pinned synthetic real-Gateway workload, not a universal SQL bound or an uninstrumented latency benchmark. The owned lease is released and verified. An intermediate attempt was stopped before any samples when main landed the archive fixture fix; it contributes no measurement evidence.
There are zero new MAIN call-site groups and zero failed SQL statements/prepares. MAIN loses one entry-snapshot freshness read per request. Cold restoration adds five necessary transaction-local authority reads, offset by removed preparation reads; source inspection alone cannot establish a universal net SQL bound. Earlier ordinary-turn measurements remain historical evidence, not second-integration proof.
Investigated failures
The deterministic UI-components type error is inherited:
terminal-panel-fonts.test.ts:56passes a stalesignalproperty tobootTerminalPanelSession. The exact command also fails on pinned main892911ba4f35in a fresh independent installation (35.04s); the entire UI tree is identical. Mainde38a0454825still contained the same blobs. The subsequently landed fixture fix1d10375ee563bis included in the third integration. No assertion or production signature was weakened.The second-integration local worker-abort file has two new failures: the no-preview case timed out before live start (one connection, no provider call), and the preview/no-fence case returned the stopped-history warning. The latter reaches
chat.abortand differs from the earlier pre-fence CI failure. Five standalone full-file runs on the second integration and five on its pinned main baseline all passed 8/8 tests on isolated Linux. That does not explain the original failures. The original infra-trio order was then verified and passed 41/41 on each revision. Neither local failure recurred, and the underlying mocked persistence error was not retained. No passing replay or newer worker change is claimed as a fix.Earlier CI run 37591153471 first hit two unchanged metadata cases with
database is locked. Five head and five baseline full-file runs completed: head 445/445, baseline 444/445, with one different baseline SQLite-busy case. Both exact CI cases passed all ten comparisons. This supports fixture contention but does not prove those exact failures inherited. The single authorized job rerun passed; that is not claimed as a repair. Remaining fail-fast cancellations were then resumed.The resumed attempt failed four worker-abort fence cases before reaching their fence actions. All ten head/baseline full-file repetitions reproduced that family; baseline repetitions directly reproduced all four cases, and scheduled main CI showed the same failure. Main subsequently repaired config-capture/cleanup ordering (#166529), fatal transcript replay, and borrower retention. Those fixes are included in the second integration instead of using an obsolete inherited-failure waiver.
The original head's durable-retry admission error occurred during fixture seeding. The exact case passed five original-head and five baseline runs; later isolated Linux main proof passed all 77 cases. It remains unreproduced, with no repair or exact-case inherited waiver claimed. The separate PR-context failure was corrected to the required problem heading.
Second-integration CI 37615797025 had two failed Node roots, its downstream aggregate failure, 73 successful jobs, 23 skips, and 16 fail-fast cancellations. The root cases are independently present on main: archive/worker-placement admission invalidation in main run
37608245742, job112749126965, and all four owner-continuation cases in that main run's job112749127206and newer main run37614737482, job112770574453. The inspected fixture and failure-owner files are unchanged. Five single-file main1b395594repetitions are complete for each file: archive fails three of five; continuation repeats all four failures in every run. The archive cleanup repair is included in the latest integration; all 15 archive and six category cases now pass. Continuation-specific code and fixtures remain byte-identical throughf2c5ed82and the final candidate; the PR-modified shared admission layers are indirectly reachable, so inherited qualification relies on independent main reproduction, not an unreachability claim. The exact completion-close cause remains unproven. The cancelled coverage is not claimed as passing.ClawSweeper completed the second integration at 2026-10-07 11:52 UTC with no actionable code or design findings; it requested completion of the disclosed worker-abort investigation. That investigation is complete as documented above. ClawSweeper also completed the latest head at 2026-10-07 12:50 UTC with no actionable code or security findings and accepted the worker-abort investigation. Its sole requested next step was recording final runtime and SQL validation; both are now complete above. No all-green CI claim is made for inherited-failure admission.