Skip to content

refactor(sessions): decouple followup custody from task projections - #158702

Merged
steipete merged 10 commits into
mainfrom
codex/session-followup-owner-prereq
Sep 26, 2026
Merged

steipete merged 10 commits into
mainfrom
codex/session-followup-owner-prereq

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Related: #156532

What Problem This Solves

Moves sessions_send follow-up result custody out of Tasks before the Tasks runtime retires.

User Impact

Follow-up replies retain their existing behavior across yields and resumed child-completion waves. Caller/session authority, lost-acknowledgment reconciliation, single-consumer results, and cancellation remain enforced. Tasks controls remain available in this prerequisite. There are no schema, protocol, configuration, or dependency changes.

Why This Change Was Made

The session/subagent completion owner now makes execution, cohort-adoption and result-custody decisions. Tasks is a projection adapter that preserves existing receipt writes and confirmed cancellation results. Generation retirement closes pending results, and concurrent cancellation calls join through projection settlement. The later removal can delete the adapter without deleting generic follow-up behavior.

Evidence

All 136 focused cases pass, including real Gateway/SQLite receipts, caller authorization, yielded successors, cancellation commit/rejection and Incognito output. Negative controls reproduced lifecycle-retirement and cancellation-join failures before their corrections. Types, lint, formatting, size/assertion ratchets, import-cycle checks (zero runtime cycles), and fresh independent P2 review pass.

The extraction build passes in 7m27.2s; later authority-guard corrections pass all affected compiler graphs. It reports an advisory startup-JavaScript budget warning; this prerequisite includes no UI source changes. The seven-file focused test run took 115.70s wrapper wall. The generic 13-case file took 1.03s Vitest wall; the two added real cancellation cases took 1.061s and 1.056s. CI timing will be recorded once available.

The final terminal-write audit covers every production caller. Real Gateway/SQLite regressions reproduce stale unstarted, paused-cancellation and ordinary-completion writes, then pass with current ownership checked at the actual commit boundary. The final 128-case owner/cancellation selection, core and all 25 selected test type graphs, and fresh P2 review pass. The nine-case durable regression file takes 25.82s wrapper wall. Guard audit, preserved cleanup contracts, and separate main-side CI diagnosis.

@clawsweeper

clawsweeper Bot commented Sep 26, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: XL labels Sep 26, 2026
@steipete
steipete marked this pull request as ready for review September 26, 2026 06:34
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 11:46 AM ET / 15:46 UTC (Revision 9).

ClawSweeper review

What this changes

Moves ownership of sessions_send follow-up replies to session and subagent completion while Tasks continues to record receipts and cancellation outcomes.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main still holds follow-up completion in Tasks, while this branch provides a distinct prerequisite to the open Tasks-retirement work. The prior receipt-commit findings appear addressed at the reviewed head.

Priority: P2
Reviewed head: 9408abfd26f226c47b74e0c7a0697bdd07554d43

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has strong boundary-focused evidence and no identified correctness finding, with a substantial but explained internal cutover.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed session owner and Task projection are exercised through production Gateway dispatch and the SQLite worker with injected revocation and replacement races; the tests inspect authorized commits and rejected pre-commit writes. The PR reports passing focused runs, and no stored-data format changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed session owner and Task projection are exercised through production Gateway dispatch and the SQLite worker with injected revocation and replacement races; the tests inspect authorized commits and rejected pre-commit writes. The PR reports passing focused runs, and no stored-data format changes.
Evidence reviewed 8 items Current main still uses Task custody: The fetched main revision imports and binds TaskFollowupCompletion in Gateway task tracking; the session-owned class and projection are absent.
Session custody and Task projection: The introduced owner retains the reply across executions; the separate Task adapter retains receipt settlement and cancellation acknowledgment.
Final receipt guard: The projection checks live follow-up and Task ownership, plus the caller-specific assertion, in the callback passed to the receipt writer. The existing SQLite worker admission checks that callback at transaction and commit stages.
Findings None None.
Security None None.

How this fits together

An agent's sessions_send call asks the Gateway to run work in another session and return a reply. Session completion holds that reply across child-completion waves, while Tasks records the receipt and cancellation result.

flowchart LR
A[Agent sends to session] --> B[Gateway admits run]
B --> C[Session follow-up owner]
C --> D[Child completion waves]
D --> C
C --> E[Reply to requester]
C --> F[Task receipt projection]
F --> G[SQLite task receipt]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +302, Tests +555. Total +857 across 24 files.

View PR surface stats
Area Files Added Removed Net
Source 15 571 269 +302
Tests 9 859 304 +555
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 24 1430 573 +857

Review metrics

Metric Value Why it matters
Production and test LOC production +572/-270 (net +302); tests +858/-303 (net +555) The PR explains production growth through the new custody owner, retained Task projection, and commit guards.
Durable regression cost 9 cases; 25.82 s wrapper wall reported These cases cover the SQLite receipt boundary, where the authority races become observable.

Technical review

Best possible solution:

Session completion should remain the sole follow-up result owner, with Tasks retained as a replaceable receipt projection until its separate retirement is ready.

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

Not applicable: this is an ownership refactor rather than a reported current-main failure. The focused tests exercise the behavior it must preserve.

Is this the best way to solve the issue?

Yes: placing reply custody with session completion and keeping Tasks as a receipt adapter follows the repository's one-owner boundary without changing the stored contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e5bf1c06109b.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded internal reliability prerequisite with limited direct user-visible change.
  • merge-risk: 🚨 session-state: Moving reply custody across yielded executions could mis-associate or strand a result if the handoff regresses.
  • merge-risk: 🚨 security-boundary: Requester and run authority now passes through a separate projection before the final SQLite receipt write.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed session owner and Task projection are exercised through production Gateway dispatch and the SQLite worker with injected revocation and replacement races; the tests inspect authorized commits and rejected pre-commit writes. The PR reports passing focused runs, and no stored-data format changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed session owner and Task projection are exercised through production Gateway dispatch and the SQLite worker with injected revocation and replacement races; the tests inspect authorized commits and rejected pre-commit writes. The PR reports passing focused runs, and no stored-data format changes.

Evidence

What I checked:

  • Current main still uses Task custody: The fetched main revision imports and binds TaskFollowupCompletion in Gateway task tracking; the session-owned class and projection are absent. (src/gateway/agent-turn/agent-run-task-tracking.ts:20, e5bf1c06109b)
  • Session custody and Task projection: The introduced owner retains the reply across executions; the separate Task adapter retains receipt settlement and cancellation acknowledgment. (src/tasks/task-followup-projection.ts:47, 9408abfd26f2)
  • Final receipt guard: The projection checks live follow-up and Task ownership, plus the caller-specific assertion, in the callback passed to the receipt writer. The existing SQLite worker admission checks that callback at transaction and commit stages. (src/tasks/task-followup-projection.ts:159, 9408abfd26f2)
  • Final-effect regression coverage: The added Gateway dispatch and SQLite worker tests inject requester revocation, completion-owner replacement, lifecycle rotation, and physical-run replacement around the terminal write, then inspect the stored receipt. (src/gateway/agent-turn/agent-run-task-tracking.cleanup.test.ts:163, 9408abfd26f2)
  • Cancellation acknowledgment coverage: The Task-owner test joins concurrent paused cancellations and checks the actual SQLite row after commit, pre-commit revocation, and owner replacement. (src/tasks/task-run-owner.test.ts:614, 9408abfd26f2)
  • Review continuity: The latest commit changed no source or tests relative to the preceding completed ClawSweeper review, which reported no findings. Earlier receipt-commit findings were addressed in intervening commits. (9408abfd26f2)

Likely related people:

  • RoboClaw: Raw commit b580769 adds src/agents/tools/sessions-send-followup.ts:34 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b580769e0bab; files: src/agents/tools/sessions-send-followup.ts)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (8 earlier review cycles)
  • reviewed September 26, 2026, 2:57 AM ET / 06:57 UTC sha unknown :: needs real behavior proof before merge. :: [P1] Carry the admission guard into the receipt commit
  • reviewed 2026-09-26T07:07:41.598Z sha d9a669d :: needs real behavior proof before merge. :: [P1] Carry admission authority into the final receipt write
  • reviewed 2026-09-26T08:00:56.710Z sha 2bec40d :: needs real behavior proof before merge. :: [P1] Carry caller authority into the paused cancellation commit
  • reviewed 2026-09-26T09:36:49.843Z sha 0678f73 :: needs real behavior proof before merge. :: [P1] Recheck follow-up custody at every terminal receipt commit
  • reviewed 2026-09-26T10:49:53.098Z sha ff57161 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T12:15:16.723Z sha a7213eb :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T13:56:14.041Z sha c20c6f7 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T14:53:00.345Z sha 6f1a3a9 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 26, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 26, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

The terminal-write audit is complete across all three production paths: ordinary completion, unstarted rejection, and paused cancellation. The shared projection now rechecks the logical owner's live requester/lifecycle custody before the write and after acknowledgment, and its additional path-specific guard is required by the type signature. Each caller carries the same physical-admission or caller/source/cohort check used by the previous owner.

Real Gateway dispatch and SQLite worker races reproduced the gaps before correction. The final 128-case owner/cancellation selection passes, covering requester revocation without an abort signal, logical-owner replacement, lifecycle rotation, physical-instance replacement, paused pre-commit revocation, post-commit cancellation cleanup, and original unaccepted receipt cleanup. The nine-case durable regression file takes 25.82 seconds wrapper wall; test setup uses the existing database-worker lane and no sleeps, polling, or extra Gateway boots. Core and all 25 selected test type graphs, lint, formatting, and fresh independent P2 review pass.

Accepted native-stop cleanup and cancellation after a committed receipt retain their existing semantics. The path-specific caller guard runs before the write; it does not retroactively revoke a completed cancellation. All three reported custody findings are addressed without introducing a new authorization policy or storage shape.

The previous CI failures were separately attributed to unchanged main-side fixtures. Main 6c7544adc9826fa637425a2fa967389e0507a800 joins database resource cleanup before reopening; captured-order replay passed 838 tests. Main a53efa5e72513169c225c3fab8495c9e8c16eae4 removes redundant compiler services from an already-compiled lint fixture while retaining real oxlint and every cleanup assertion. Its original exact surviving process remains unknown; the recorded passing baseline is not labeled a fix. The current head refreshes CI against those repairs and is tree-identical to the reviewed production change.

@steipete
steipete enabled auto-merge (squash) September 26, 2026 14:55
@steipete
steipete disabled auto-merge September 26, 2026 14:59
@steipete
steipete merged commit a94ad94 into main Sep 26, 2026
228 checks passed
@steipete
steipete deleted the codex/session-followup-owner-prereq branch September 26, 2026 16:03
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
…penclaw#158702)

* refactor(sessions): decouple followup custody from task projections

* test(sessions): align cancellation timeout with Gateway owner

* fix(sessions): fence followup cleanup at receipt commit

* fix(sessions): preserve paused cancellation authority through commit

* fix(sessions): revalidate logical custody at terminal projection

* ci: refresh followup checks after main lint fixture cleanup

* ci: refresh followup checks after QA protocol reference repair

* ci: refresh followup checks after fetch fixture repair

* ci: refresh follow-up custody proof after fixture repair

* ci: refresh follow-up checks after database admission repair
steipete added a commit that referenced this pull request Sep 27, 2026
Remove Tasks and TaskFlow runtime, APIs, CLI, SDK surfaces and panels after the Cron, session, native execution and media completion ownership cutovers. Preserve stored rows and import provable legacy native assignments through Doctor; ambiguous ownership stays untouched with a warning.

Follows #158221, #158217, #158225, #158222, #158702 and #158776. Related: #156532. Task-specific public APIs retire immediately; retained responsibilities use their existing owners.

Maintainer-authorized administrative landing after full CI run 36312986498 attempt 2 passed on 274595e, with subsequent actual conflicts reviewed and focused checks passing. Current PR CI preflight hits the 64 KiB changed-path metadata limit before tests (run 36335042695); its duplicate security-review status mirrors that planning failure. Review and scoped proof are recorded in the PR. Published 9.4 native import is proven; remaining native completion and 9.4 rollback witnesses are explicitly unproven.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 28, 2026
Remove Tasks and TaskFlow runtime, APIs, CLI, SDK surfaces and panels after the Cron, session, native execution and media completion ownership cutovers. Preserve stored rows and import provable legacy native assignments through Doctor; ambiguous ownership stays untouched with a warning.

Follows openclaw#158221, openclaw#158217, openclaw#158225, openclaw#158222, openclaw#158702 and openclaw#158776. Related: openclaw#156532. Task-specific public APIs retire immediately; retained responsibilities use their existing owners.

Maintainer-authorized administrative landing after full CI run 36312986498 attempt 2 passed on 274595e, with subsequent actual conflicts reviewed and focused checks passing. Current PR CI preflight hits the 64 KiB changed-path metadata limit before tests (run 36335042695); its duplicate security-review status mirrors that planning failure. Review and scoped proof are recorded in the PR. Published 9.4 native import is proven; remaining native completion and 9.4 rollback witnesses are explicitly unproven.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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.

1 participant