Repository navigation
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
Codex review: needs maintainer review before merge. What this changesThis PR removes inherited foreground caller and operator authority before session maintenance executes. Example: A target session replies to sessions_send with timeoutSeconds: 0 after the source turn completes.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current maintenance failure at the existing owner without introducing a competing path; no actionable patch defects were found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherReply completion schedules optional maintenance, which acquires target-session admission before memory flushing and transcript compaction. flowchart TD
A[Completed reply] --> B[Maintenance scheduler]
B --> C[Session maintenance owner]
C --> D[Exit source authority scopes]
D --> E[Target session admission]
E --> F[Memory flush and compaction]
F --> G[Authorized transcript persistence]
Technical reviewBest possible solution: Land the existing owner-level scope isolation once required checks complete successfully. Do we have a high-confidence way to reproduce the issue? Current-main source preserves the stale asynchronous authority path, and supplied frozen-main Gateway runs record its failure; no target code was executed during this review. Is this the best way to solve the issue? Exiting both inherited scopes at the shared maintenance owner fixes the cause while preserving target-owned admission, ordering, cancellation and effect authorization. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9dd47e67ded4. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +7, Tests +148. Total +155 across 3 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (5 earlier review cycles)
Reviewed October 16, 2026, 10:45 PM ET / October 17, 2026, 02:45 UTC (Revision 6). |
…fore post-turn compaction Optional session maintenance was scheduled from within the foreground turn's AsyncLocalStorage context, causing it to inherit the GatewayToolCallerIdentity set by the foreground turn. When the maintenance's tool activation later called captureGatewayToolCallerAssertion(), the captured receiptAuthority check fired against the now-retired foreground turn and threw 'agent tool caller authority is no longer active'. Use withoutGatewayToolCallerIdentity() (which calls AsyncLocalStorage.exit()) to wrap the withPluginRuntimeGatewayRequestScope launch. This clears the ALS slot before the async chain starts, so all downstream work including compaction tool setup runs without any foreground caller authority — exactly the contract the existing withoutGatewayToolCallerIdentity docstring describes. captureGatewayToolCallerAssertion() and receiptAuthority remain unchanged; legitimate revocation of active calls is fully preserved. Tests: two new regression tests confirm (1) getGatewayToolCallerIdentity() is undefined inside the maintenance scope when called from a stale foreground context, and (2) captureGatewayToolCallerAssertion() returns undefined rather than a throwing function. Both fail on the unfixed baseline.
85734cd to
c378f93
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
…mpaction-authority # Conflicts: # src/agents/session-maintenance/run.ts
|
@clawsweeper re-review The PR body now records observed frozen-main failures and successful candidate delegated/direct compaction, actual source-grant rejection in maintenance, zero maintenance provider/persistence effects after reset/deletion, foreground preemption, and measured focused test timing. The four earlier proof blockers are addressed. Current head 60c8336 differs from the exercised production head only by removing an excess property from a test scope. Please review this exact head; do not merge. |
|
🦞👀 Re-review progress:
|
…mpaction-authority
|
@clawsweeper re-review Current head is 4fd16c9 after merging the main CI repair #174947. Targeted diffs confirm the maintenance owner, scheduler, and reply-maintenance adapter are unchanged from the exercised E2E head 459b3ce; tests are unchanged from the one-property type repair 60c8336. The PR body records observed successful delegated compaction twice, direct-chat controls, source-grant denial, zero maintenance effects after reset/deletion, foreground preemption, and focused test timing. Please review this exact head; do not merge. |
|
🦞👀 Re-review progress:
|
|
Landed as 5fbb405.
Thanks @ethanhawkes-gif for the fix. |
…nclaw#159353) Related: openclaw#158070, openclaw#171668 ## What Problem This Solves Fixes automatic post-turn compaction failing after a target session replies to `sessions_send` with `timeoutSeconds: 0` and the source turn has already completed. ## User Impact Delegated target sessions compact after delivery instead of retaining an overfull context. No configuration, stored-row schema, or protocol changes are introduced. ## Why This Change Was Made Extends @ethanhawkes-gif's fix at the existing session-maintenance owner rather than retaining a separate scheduling wrapper. The owner drops the launching turn's Gateway caller and operator-tool scopes, using the same isolation primitives as openclaw#171668. Both direct-chat and delegated maintenance then use the target's existing maintenance ownership, lifecycle checks, writer admission, session revision checks, cancellation, and pre-effect authorization. No source grants are copied or new ambient grants created. The original 597-line integration fixture is replaced with focused tests in the existing owner/admission suites. Its old negative fixture supplied an empty Gateway context, which made every case fail the Gateway fence irrespective of the intended invalidation; the replacement includes a functioning Gateway resolver and a matched successful control. The complete delta against merged main is production +9/-2 and tests +151/-3 across three files. ## Evidence Frozen main: `964a9ea2957cdb7a6566daf3d927691ad06a8557`. Current head: `4fd16c989c99be3d10aefaf81965df8a6cc89482`. Runtime proof and focused tests: `459b3ce72bc2b2c8f4939efe39c260af13164916`. The initial merge used main `8f3292fff6a`; the later CI-repair merge includes main `01edef4f3f37deb66bf4e448ac2ff30f8b644771`. Targeted diffs show the maintenance owner, scheduler, and reply-maintenance adapter are byte-for-byte unchanged from the E2E head. Tests are unchanged from `60c83362dbc`, which only removed an unused excess `sessionId` property from a test's `SessionAccessScope`. | Cell | Observed on frozen main | Candidate | | --- | --- | --- | | Real source chat → `sessions_send(timeoutSeconds: 0)` → target reply, repeat 1 | Both replies delivered; optional maintenance failed with `agent tool caller authority is no longer active`; zero compaction provider calls | Both replies delivered; two compaction provider calls; durable compactionCount 1; tokens 125000 → 62206 | | Same delegated flow, repeat 2 | Same failure; target retained 125000 tokens and compactionCount 0; health passed | Same successful compaction; durable compactionCount 1; tokens 125000 → 62206; health passed | | Direct-chat control, two repeats | Both compacted; compactionCount 1, tokens 60050 → 43996, two compaction provider calls each | Both compacted; compactionCount 1, tokens 60050 → 44113; two compaction provider calls each; health passed | | Manual `sessions.compact` control | Succeeded; tokens 125050 → 6664, compactionCount 1 | Reports `Already compacted`, since automatic maintenance already succeeded | Observed security cells through a real isolated Gateway, loopback provider, and diagnostic plugin: | Boundary | Observed result | | --- | --- | | Source tool grants | Actual source `cron.list` succeeds. The identical call from target maintenance fails with `trusted agent runtime identity required for this gateway call`; target compaction still succeeds with two provider calls and one durable compaction. | | Target reset before maintenance | Reset completes before releasing the held target response. Zero maintenance provider calls; zero new compaction entries/windows/count. | | Target deletion before maintenance | After the endpoint's explicit changed-owner refusal, one fresh deletion request succeeds with `deleted: true`. Target row absent; zero maintenance provider calls or compaction persistence. | | Foreground preemption | Foreground arrival cancels held maintenance. Before allowing the successor to proceed, SQLite still has compactionCount 0 and no compaction entries/windows; stale summary is never persisted. The foreground reply then completes, and its fresh maintenance may compact normally. | Lifecycle-generation and Gateway-instance retirement are separately covered before admission and after awaited flush in the focused admission tests. Failed/aborted foreground settlement and actual cancellation cleanup retain their existing owner tests. No invalidation case relies solely on a matching session ID. Install/build succeeded once. Formatting and focused lint passed. Owner tests: 19 passed, 11.64 s one-file wall time (Vitest 6.62 s). Admission/authority-loss tests: 8 passed, 91.46 s wall time (Vitest 81.50 s, including 48 s cold worker preparation). Existing scheduler test: 1 passed, 63.30 s wall time. Initial copied-install dependency failures were resolved by the install. The identical delegated/direct baseline harnesses changed only the candidate path, evidence destination, and recorded SHA. The negative fixture's first startup attempt matched the wrong readiness log text; the Gateway had become ready, and correcting the event match did not change any timeout or product behavior. Hosted CI on `459b3ce` found the test-only excess-property error fixed by `60c83362dbc`, plus an inherited `checks-fast-baseline-ratchets` mock-exports error. Main fixed that ratchet in openclaw#174947; this head includes that repair through the main merge, without an independent fixture workaround. [Exact-head CI](https://github.com/openclaw/openclaw/actions/runs/38995088011) is green. [ClawSweeper's exact-head review](openclaw#159353 (comment)) is `ready`, with no findings or remaining proof blockers. No merge has been performed. **Merge danger:** two-way door; reverting restores the previous ownership behavior without a migration. The security-boundary blast radius is optional session maintenance across direct and delegated agent turns. An incorrect scope transition could deny valid maintenance or retain source privileges; the allowed/revoked final-effect cells above protect that boundary. Co-authored-by: Ayaan Zaidi <[email protected]>
Related: #158070, #171668
What Problem This Solves
Fixes automatic post-turn compaction failing after a target session replies to
sessions_sendwithtimeoutSeconds: 0and the source turn has already completed.User Impact
Delegated target sessions compact after delivery instead of retaining an overfull context. No configuration, stored-row schema, or protocol changes are introduced.
Why This Change Was Made
Extends @ethanhawkes-gif's fix at the existing session-maintenance owner rather than retaining a separate scheduling wrapper. The owner drops the launching turn's Gateway caller and operator-tool scopes, using the same isolation primitives as #171668. Both direct-chat and delegated maintenance then use the target's existing maintenance ownership, lifecycle checks, writer admission, session revision checks, cancellation, and pre-effect authorization. No source grants are copied or new ambient grants created.
The original 597-line integration fixture is replaced with focused tests in the existing owner/admission suites. Its old negative fixture supplied an empty Gateway context, which made every case fail the Gateway fence irrespective of the intended invalidation; the replacement includes a functioning Gateway resolver and a matched successful control. The complete delta against merged main is production +9/-2 and tests +151/-3 across three files.
Evidence
Frozen main:
25933024a1e197fa1a503e84b573a47203fc674f.Current head:
4fd16c989c99be3d10aefaf81965df8a6cc89482. Runtime proof and focused tests:459b3ce72bc2b2c8f4939efe39c260af13164916. The initial merge used main51ea9e50ecb; the later CI-repair merge includes main4513e9e09633a740f58b4ccf8802597968868c47. Targeted diffs show the maintenance owner, scheduler, and reply-maintenance adapter are byte-for-byte unchanged from the E2E head. Tests are unchanged from60c83362dbc, which only removed an unused excesssessionIdproperty from a test'sSessionAccessScope.sessions_send(timeoutSeconds: 0)→ target reply, repeat 1agent tool caller authority is no longer active; zero compaction provider callssessions.compactcontrolAlready compacted, since automatic maintenance already succeededObserved security cells through a real isolated Gateway, loopback provider, and diagnostic plugin:
cron.listsucceeds. The identical call from target maintenance fails withtrusted agent runtime identity required for this gateway call; target compaction still succeeds with two provider calls and one durable compaction.deleted: true. Target row absent; zero maintenance provider calls or compaction persistence.Lifecycle-generation and Gateway-instance retirement are separately covered before admission and after awaited flush in the focused admission tests. Failed/aborted foreground settlement and actual cancellation cleanup retain their existing owner tests. No invalidation case relies solely on a matching session ID.
Install/build succeeded once. Formatting and focused lint passed. Owner tests: 19 passed, 11.64 s one-file wall time (Vitest 6.62 s). Admission/authority-loss tests: 8 passed, 91.46 s wall time (Vitest 81.50 s, including 48 s cold worker preparation). Existing scheduler test: 1 passed, 63.30 s wall time. Initial copied-install dependency failures were resolved by the install. The identical delegated/direct baseline harnesses changed only the candidate path, evidence destination, and recorded SHA. The negative fixture's first startup attempt matched the wrong readiness log text; the Gateway had become ready, and correcting the event match did not change any timeout or product behavior.
Hosted CI on
459b3cefound the test-only excess-property error fixed by60c83362dbc, plus an inheritedchecks-fast-baseline-ratchetsmock-exports error. Main fixed that ratchet in #174947; this head includes that repair through the main merge, without an independent fixture workaround. Exact-head CI is green. ClawSweeper's exact-head review isready, with no findings or remaining proof blockers. No merge has been performed.Merge danger: two-way door; reverting restores the previous ownership behavior without a migration. The security-boundary blast radius is optional session maintenance across direct and delegated agent turns. An incorrect scope transition could deny valid maintenance or retain source privileges; the allowed/revoked final-effect cells above protect that boundary.