Skip to content

refactor(sessions): await input completion and collapse suggestion writes - #169573

Merged
steipete merged 14 commits into
mainfrom
dbasync/t1cut-s7
Oct 12, 2026
Merged

steipete merged 14 commits into
mainfrom
dbasync/t1cut-s7

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Core-created user-turn recorders could still complete pending input through a native SQLite mutation. Suggestion commands also entered a second transaction inside their existing worker transaction and read the session identity twice. This change moves bundled completion callers to the awaited owner and removes the redundant suggestion work. The released synchronous SDK adapter remains deprecated until the next SDK major.

Core callers await completion. Host-created recorders preserve the deprecated completeProcessing adapter, its immediate return and transaction semantics, and emit a deprecation warning naming completeProcessingAsync. Plugin-supplied legacy callbacks remain accepted only when no async companion exists. Bundled completion fixtures use the async API. Suggestion worker commands call the shared database kernels directly in their existing transaction; one expected-entry comparison supplies the session identity and sharing authority check.

Reaction listing has an awaited worker API. Catalog authorization consumes the projection owner's published membership facts, and transcript annotation leaves its exact-row check to the writer. There are no schema, format, retention, permission, or production Doctor/update changes; the Doctor test changes only await their completion fixtures.

T1 accounting and retained boundaries

The assigned files still contain 50 T1 call expressions. This PR does not claim a static T1 reduction or completion of the entire lane. Bundled completion callers use the worker, but the kernels remain shared with native-incognito or deprecated synchronous SDK adapters. Follow-up after #169363 removes the excluded native-incognito callers; shared files are not relabeled as worker-only prematurely.

Assigned family Base T1 Candidate T1 Retained caller
Pending-input history/source/operations/store 15 15 Native-incognito paths pending #169363 and deprecated SDK completion; bundled callers await the worker
Reactions 7 7 Native-incognito owner
Suggestions 12 12 Native-incognito wrappers; durable worker commands bypass them
Sharing 7 7 Native-incognito and final membership authorization
Transcript index/FTS 9 9 Deprecated synchronous SessionManager/opaque callback adapters, plus incognito and maintenance

Final membership checks before privileged effects remain: the authority owner still permits native SDK writers, so a prepared hint cannot replace those checks. Existing synchronous SessionManager and transcript adapters retain their documented deprecations, runtime warnings, and async replacements.

Removed checks and accepted edges

  • Removed native handle/revision recapture after a confirmed pending-input worker receipt. An unrelated committed write between settlement and publication no longer rejects a successful receipt.
  • Removed the annotation preflight projection-status read. A dirty index does not reject an annotation whose exact transcript anchor still passes the writer's check.
  • Removed suggestion session-ID rereads when the same ID was already checked with the full expected entry. Conflicting supplied IDs still reject without another SQL read.
  • Reused current published catalog membership rather than reading it again through the synchronous role fallback. Membership follows the projection owner's write receipts.
  • Removed the two preliminary suggestion-mutation permission checks. The effect guard retains current owner-published membership; malformed unauthorized input may receive a generic validation error before permission denial.

Measurement

The shared workload ran locally against isolated synthetic state, using the unchanged shared harness plus its established request census. Baseline 7f337b2c5a20033c89304d030045fa0fe0338e13; candidate e7066e0deb77098a675ab4618ee40f8e95f0b8f4. The final merge of main preserved this implementation and accepted main’s generated inventory snapshot; this PR no longer changes the generated inventory. RELAXED TESTING v6 permits one pair. This valid pair is retained. Two attempted additional comparisons are excluded under the existing duration-skew rule: one had 1.69× candidate/baseline warmed duration; its replacement had 1.78× first-turn duration (2.06× boot and 2.80× connect). No result is selected by SQL count. The final SDK compatibility restoration is dormant on these bundled async flows; the later fixture fix changes tests only.

Valid pair (mean over ten warmed turns; one valid pair means the median and range coincide):

Metric Baseline Candidate Delta
All-thread statements / warmed turn 334.6 325.9 -8.7
Requests / warmed turn 103.4 100.9 -2.5
MAIN statements / warmed turn 0.2 0.2 0
Whole-workload statements 9,828 9,666 -162
Whole-workload requests 2,023 1,964 -59

These workload differences include scheduled background work; they are not all attributable to this patch.

Cold/adjacent window Baseline statements Candidate statements Delta
Boot + connect + first turn 4,106 4,109 +3 (+0.073%)
Second session + control plane + cron 2,068 2,043 -25
Compaction + shutdown 308 255 -53

The first-turn slice alone is 1,881 → 1,966, but its unchanged deferred open/admission work moved across startup boundaries: open adds 67 in that slice and falls by 9 across the combined startup window. Other shifted owners include database.domain.publish, deletion snapshots, and registry inventory. Startup requests are 337 → 341 (+1.19%); the warmed and whole-workload requests fall. The second-session increase (+86) consists mainly of domain publication (+37), subagent persistence (+20), and delivery settlement (+6), which leave the adjacent control/cron window. These are existing background operations, not new commands from this patch. The combined startup statement difference is below TURN NOISE FLOOR; the cold request movement is within the T1 MOVE EXCEPTION, with no warmed increase. All 13 turns, child execution, cron, compaction, and shutdown completed. The baseline's optional mention-dismiss probe returned Inbox unavailable after the warmed turns; the candidate completed it. The baseline runner's final blanket RPC assertion therefore failed, while its workload results and SQL census were complete.

Real async suggestion-owner probe, counting the owning worker command (one request and zero MAIN statements in every cell):

Operation Baseline statements Candidate statements Delta
Add with expected entry 10 7 -3
Claim with expected entry 9 6 -3
Release 6 4 -2
Reclaim with expected entry 9 6 -3
Dismissed finalization with expected entry 9 6 -3

Deferred open/admission work emitted two additional statements in the baseline release/reclaim windows and candidate release window; it is excluded from the per-command table and included in raw phase totals.

Evidence

  • Two isolated Codex autoreview rounds completed. The later ClawSweeper finding about the released host completion callback was accepted and fixed: the deprecated adapter, immediate results, outer-rollback behavior, and postcommit behavior remain. Its requested additional catalog test is a follow-up; no bypass was established, and the handler re-prepares the owner projection after awaited enumeration and checks membership before the effect. The final two-call suggestion authorization cleanup also received an independent source audit.
  • Local basic proof on the integrated diff: oxfmt, oxlint, and git diff whitespace check passed. No further local Vitest/typecheck/check:changed runs under RELAXED TESTING v6.
  • Earlier committed-head focused proof: 255 passed / one failed across 17 files (887 seconds). The failure was a worker error-constructor identity assertion; after fixing that assertion the suggestion suite passed 7/7 (198 seconds), and the migrated catch-up fixture passed 16/16 (178 seconds). Tests and static checks run in PR CI; completed and pending heads are distinguished below.
  • Main's identical chat identity test failure: run 38205326916, job 114667657563. The previous PR run was cancelled by fail-fast after this inherited failure; ci:no-fail-fast is enabled for the integrated-head run.
  • Main's Knip failure names untouched UI files and agentRunHasVisibleReply / retireOpenClawStateReadConnectionAfterCorruption. Ordinary PR CI excludes the dependencies job. No passing Knip claim is made.
  • Integrated production/test types (apart from one subsequently fixed stale target fixture), lint, Madge, export/source contracts, SDK boundary and worker/dialect ratchets passed in run 38210849636, as did all Node tests. The previously integrated head 3d5ae552ee97fdc7c0c5b9007c78ad3fe157459d passed every static job and build-artifacts in run 38214326082. The new host recorder regression passed (1017 ms), all 15 pending-input-operation tests passed, and the async completion test confirms no caller-thread SQL. Its changed-file test group completed 136 tests in 30.70 seconds; no local suites were run under v6. The standalone SDK API diff did not complete; the released callback surface and implementation remain, and the SDK/extension boundary is covered by CI.
  • Final head 9357a5d8e538f775197c35d86d0087d85bcb014d completed CI 38218346987. All production/test type shards, all lint shards, source/export contracts, Madge, SDK/extension boundaries, and worker/T1/dialect ratchets passed. Knip has the separately documented inherited main failures above; no passing standalone Knip claim is made.
  • Three non-static failures remain independently attributed, without claiming a reproduced-main failure: (1) small-6 repeats the untouched stale-version actor postimage test, failing in actor append before changed code; (2) large-11 sees two upstream-link SELECTs instead of one in the unchanged Bun rewind census. Its counter, upstream reader/cache, fork and final-guard chain match merged main; this patch adds no upstream-link operation. The reason that existing cache missed is unresolved. (3) build-artifacts completed build but failed its concurrent-delete CLI proof because the deliberately deleted run returned a terminal AbortError without stopReason. The unchanged delete drain closes admitted work with that exact error before explicit controller cancellation, and the unchanged error publisher omits stopReason on that path. Attribution to that existing race is source-based; no stack or failing-main reproduction proves the exact winning catch. The same built proof passed on the prior integrated head. These failures remain recorded; no test or assertion was relaxed.
  • Native review/preparation repeatedly spent more than ten minutes in local Git/metadata setup; the authorized exact-head REST fallback is used after verifying all static gates. No test, guard, or ratchet was weakened.
  • No update cell applies: no production update, Doctor, schema/migration, plugin-loading or lifecycle implementation changed.

Final diff: production +242/-164 across 17 files; tests +259/-124 across 15 files; docs +14/-8 across 2 files (515 additions, 296 deletions total).

Follow-ups: remove the extra skills-library preparation membership authorization (the effect check remains); add production catalog revocation/replacement coverage at the existing effect guard; remove excluded native-incognito entrances after #169363, then reclassify genuinely worker-only kernels. Retained SDK/final-authorization paths keep their documented next-major retirement boundary. Memory-actor error serialization also drops the work-start-invalidated code; it safely refuses the write but can misclassify the error, outside this patch.

@clawsweeper

clawsweeper Bot commented Oct 12, 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 docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations agents Agent runtime and tooling size: L labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR consolidates suggestion transactions, moves reaction reads to workers, simplifies committed-input publication, and preserves deprecated synchronous completion callbacks.

Example: Alice suggests “Review the deployment” in agent:main:main with an expected session entry.

  • Before: The suggestion worker calls a transaction-owning facade and checks session identity separately.
  • After: The existing worker transaction calls the shared kernel and validates the expected entry once.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The storage refactor is coherent and the released callback is preserved, but the required catalog authority evidence remains absent and one exact-head runtime failure is unclassified.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Session collaboration performs redundant transaction and identity work, and confirmed input settlement can be rejected after an unrelated committed write.
Reason: The owner-directed change uses established storage owners and preserves released compatibility without adding configuration or stored formats.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep this PR open: it contains useful storage consolidation absent from current main, and the earlier synchronous completion compatibility defect is resolved; no definite introduced bug was established.

Priority: P2
Reviewed head: 9357a5d8e538f775197c35d86d0087d85bcb014d

Before merge

  • Add real behavior proof - Authority-chain proof required: the isolated Gateway workload and suggestion-owner measurements do not exercise the changed catalog authority. Show a view-capped member succeeding and a nonmember denied through the production handler, then commit membership revocation or replace the session during awaited enumeration and show rejection before archive or continuation provider I/O. Redacted logs or terminal output are sufficient; remove IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve security concern: Validate projection-backed catalog mutation authority - Catalog archive and continuation consume a membership decision derived from published projection facts; supplied evidence does not establish rejection of a nonmember or a member revoked or replaced during awaited enumeration before provider I/O.
  • Resolve merge risk - Before merge, establish that projection-backed catalog membership rejects committed revocation and session replacement before archive or continuation provider I/O.
  • Resolve merge risk - Before merge, classify the exact-head built CLI lifecycle abort using its full failure trace and a matching main failure or a head-versus-revert comparison.

Findings

  • [medium] Validate projection-backed catalog mutation authority — src/gateway/server-methods/session-catalog-visibility.ts:241

Tests

  • Missing end-to-end proof: The supplied workload does not cover catalog final-effect authorization through real membership publication, denial, revocation, or replacement; baseline failure of the added regression cases is not shown.
Agent review details

How this fits together

Gateway and agent requests enter session storage owners, which persist collaboration state and publish committed receipts and membership facts for responses and authorization.

flowchart TD
A[Gateway and agent requests] --> B[Session storage owners]
B --> C[Worker admission]
C --> D[Shared database kernels]
D --> E[Agent SQLite database]
E --> F[Committed receipts and membership]
F --> G[Catalog authorization and responses]
Loading

Technical review

Best possible solution:

Retain the worker consolidation and released SDK adapter, with catalog authority verified at provider effects and the built CLI failure attributed.

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

Current-main source shows suggestion worker commands calling transaction-owning facades and separately checking session identity; no target code was executed during this review.

Is this the best way to solve the issue?

Reusing shared kernels inside the existing worker transaction is appropriate, and preserving the synchronous callback resolves the earlier concrete compatibility defect.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against af2c00828eb3.

Merge-risk options

Maintainer options:

  1. Verify the changed authority and classify the CLI failure (recommended)
    Provide permitted and forbidden catalog final-effect traces, including committed revocation and replacement, and establish the cause of the built CLI abort.
  2. Defer projection-backed catalog authorization
    Restore the existing membership lookup in session-catalog-visibility.ts and move that optimization into a separately verified change; the CLI failure still needs attribution.

Provenance checked

  • Recorder completion compatibility keeps the original intent (d6c1b1f: Move internal completion into workers while preserving released synchronous callbacks.)
  • Suggestion storage kernels keeps the original intent (38a8904: Share connection-bound SQL while retaining validation, ordering, claims, and transaction ownership.)
  • Suggestion authorization keeps the original intent (ef27c1f: Reject stale caller and session authority before acceptance while retaining custody for accepted-input settlement.)
  • Pending-input receipt publication changes intended behavior with a stated reason (38d1253: Carry prepared custody facts while fencing native writes; this PR explicitly accepts independent commits after confirmed settlement and retains physical-owner checks.)
  • Transcript annotation preflight changes intended behavior with a stated reason (f5f44fa: Bind annotation to the admitted transcript and active anchor; this PR removes the dirty-index preflight while retaining exact-anchor and live-owner validation.)
  • Catalog membership authorization keeps the original intent (53dcaae: Require explicit membership for foreign-session mutations when the caller otherwise has view-only access.)
  • Reaction listing keeps the original intent (139d7ab: Keep reactions separate from transcript bytes; the worker reader preserves the existing query and result model.)

Testing

Proof path: shipped entry point.

Security

Needs attention: No concrete bypass was established, but the changed catalog authority source needs final-effect validation.

Evidence

Security concerns:

  • [medium] Validate projection-backed catalog mutation authority — src/gateway/server-methods/session-catalog-visibility.ts:241
    Catalog archive and continuation consume a membership decision derived from published projection facts; supplied evidence does not establish rejection of a nonmember or a member revoked or replaced during awaited enumeration before provider I/O.
    Confidence: 0.94

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit d6c1b1f adds src/sessions/user-turn-transcript.types.ts:218 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d6c1b1f9e14a; files: src/sessions/user-turn-transcript.types.ts)
  • Vincent Koc: Raw commit 7a168d3 adds src/sessions/user-turn-transcript.types.ts:212 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 7a168d3d4bdd; files: src/sessions/user-turn-transcript.types.ts)
  • Josh Lehman: Raw commit 00a75db adds src/sessions/user-turn-transcript.types.ts:75 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 00a75db4280b; files: src/sessions/user-turn-transcript.types.ts)

PR surface

Source +78, Tests +135, Docs +6. Total +219 across 34 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 17 242 164 +78
Tests 15 259 124 +135
Docs 2 14 8 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 34 515 296 +219

Review metrics

Metric Value Why it matters
Production versus test LOC Production +242/-164; tests +259/-124 Production growth adds worker read contracts and direct kernel dispatch; test growth principally preserves completion compatibility and exercises stale suggestion targets.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P2: Useful session-storage maintenance without evidence of an urgent production outage.
  • merge-risk: 🚨 compatibility: Released completion methods gain explicit deprecation while retaining their synchronous implementation and documented next-major retirement window.
  • merge-risk: 🚨 security-boundary: Foreign-session catalog mutations change their membership authority source from direct lookup to published projection facts.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add final-effect proof for permitted membership, nonmember denial, committed revocation, and session replacement before catalog provider I/O.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (7 earlier review cycles)
  • reviewed 2026-10-12T03:32:03.318Z sha 507e5ee :: needs real behavior proof before merge. :: [P1] Preserve the released host-provided completion callback
  • reviewed 2026-10-12T03:41:31.949Z sha 507e5ee :: needs real behavior proof before merge. :: [P1] Preserve the released host-provided completion callback
  • reviewed 2026-10-12T04:51:48.162Z sha ca477ad :: needs real behavior proof before merge. :: [P1] Preserve the released host-provided completion callback
  • reviewed 2026-10-12T05:49:17.688Z sha ca477ad :: needs real behavior proof before merge. :: [P1] Preserve the released host-provided completion callback
  • reviewed 2026-10-12T06:11:58.834Z sha f460570 :: needs real behavior proof before merge. :: [P1] Preserve the released host-provided completion callback
  • reviewed 2026-10-12T07:04:46.153Z sha 3d5ae55 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T07:30:28.902Z sha 3d5ae55 :: needs real behavior proof before merge. :: none

Reviewed October 12, 2026, 3:49 AM ET / 07:49 UTC (Revision 8).

@steipete steipete added the ci:no-fail-fast Keep all selected CI matrix jobs running after failures on the next PR run. label Oct 12, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Oct 12, 2026
@clawsweeper clawsweeper Bot removed the rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. label Oct 12, 2026
@clawsweeper clawsweeper Bot added the rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. label Oct 12, 2026
@steipete
steipete merged commit 893bb04 into main Oct 12, 2026
137 of 142 checks passed
@steipete
steipete deleted the dbasync/t1cut-s7 branch October 12, 2026 07:53
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…ites (openclaw#169573)

Route bundled input completion and reaction reads through the existing worker owner. Remove pending-input publication recaptures, duplicate suggestion reads and nested transaction work while retaining the deprecated released SDK completion adapter.

Live warmed workload: 334.6 to 325.9 statements and 103.4 to 100.9 requests; MAIN 0.2 unchanged. Assigned T1 remains 50 with documented native, SDK and final-authority exceptions.

Types, lint, source contracts, Madge, SDK boundaries and database ratchets passed. Independently attributed actor-postimage, upstream census and concurrent-delete reporting failures remain documented in the PR. Head-pinned fallback after native preparation stalled.
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 20, 2026
First-parent upstream fa23864..e099f44 (100 commits, including
openclaw#169594 lifecycle/mention bookkeeping in workers, openclaw#169573 input completion,
openclaw#169724 fact-only refresh rows, openclaw#169598 target discovery).

Conflicts:
- session-entry-patch-source.ts: upstream routes host-only commit guards
  through the worker (`!commitGuard?.nativeSource`); kept our condition that
  a patch with afterPersistInTransaction (a main-thread closure) stays on
  the native writer.
- compact.types.ts: our "volitional" trigger plus upstream's
  modelCallUrgency.
- session-accessor.ts: upstream dropped the sync
  updateSessionProfileInvolvement export (no fork caller); recipient
  authority exports kept.
- worker inventory regenerated.

Auto-merged files carrying continuation overlay (21) keep it byte-for-byte.

Refs #1475

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling ci:no-fail-fast Keep all selected CI matrix jobs running after failures on the next PR run. commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant