Repository navigation
perf(sessions): read first-turn transcript headers through the transcript worker - #165401
Conversation
Recover first-use lifecycle timestamps through the retained transcript reader, with writer FIFO custody and a native mutation witness. Carry current candidate facts through reply, agent, status, and Slack preparation while preserving the released synchronous SDK method and cancellation outcomes.
|
🦞👀 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: blocked before merge. Reviewed October 5, 2026, 6:56 AM ET / 10:56 UTC (Revision 8). ClawSweeper reviewWhat this changesMove missing session lifecycle timestamp reads into the existing transcript worker across agent preparation, reply initialization, status rendering, and Slack freshness checks while preserving the released synchronous plugin method. Merge readiness⛔ Blocked before merge - 3 items remain This PR still provides distinct, useful work absent from current main. No actionable correctness or security defect was found, and the previous integration conflicts are resolved. Priority: P2 Review scores
Verification
How this fits togetherSession lifecycle timestamps determine when OpenClaw reuses or resets a conversation and what duration status displays. The transcript reader supplies missing timestamps from stored headers to those decisions. flowchart TD
A[Incoming turn or status request] --> B[Session lifecycle metadata]
B --> C{Start timestamp present?}
C -->|Yes| F[Reuse or reset decision]
C -->|No| D[Existing transcript worker]
D --> E[Retained owner and freshness checks]
E --> F
F --> G[Prepared conversation or status]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +139, Tests +241, Docs +22. Total +402 across 36 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep timestamp recovery with the existing reader and reset-policy owners, preserving released synchronous callability and recording the integrated-head SDK compatibility result. Do we have a high-confidence way to reproduce the issue? Not applicable to a user-visible bug: the supplied paired Gateway workload establishes main-thread SQL placement, and source confirms the synchronous path remains on current main. No runtime execution was performed in this read-only review. Is this the best way to solve the issue? Yes. Reusing the existing transcript reader and timestamp reducer is a coherent cutover, with bundled callers migrated and the shipped synchronous plugin contract retained. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ae5a95772c02. 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 (7 earlier review cycles)
|
Merge current main while preserving transcript replay validation and its writer ownership. Keep main test cleanup and adapt the remaining command session cases to awaited resolution. Register the released synchronous reset freshness compatibility contract and add a type assertion for its retained return value alongside the async companion. No schema, reset policy, retention, or durability changes.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Merge main c2e6410 and keep the ordered reader plus its stronger revocation and cleanup tests from #165360. This removes duplicate guard hunks from the header cutover without changing the lifecycle reader or released SDK surface. The three affected reader/freshness suites pass 37 cases. Fresh P2 review is clean; the prior SDK report remains scoped to unchanged header declarations and compatibility metadata.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Merge main a1ce6fb and retain both envelope timestamp and reset freshness runtime helpers. Carry the new async timestamp helper into the shared session-runtime mock and preserve both SDK compatibility records. Place reset freshness with related session-read compatibility records to avoid competing additions at the front of the catalog. Fresh P2 review is clean; the released synchronous freshness signature remains unchanged.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…ript worker (openclaw#165401) * perf(sessions): read lifecycle timestamps through workers Recover first-use lifecycle timestamps through the retained transcript reader, with writer FIFO custody and a native mutation witness. Carry current candidate facts through reply, agent, status, and Slack preparation while preserving the released synchronous SDK method and cancellation outcomes. * fix(gateway): preserve cancellation outcomes during async preparation * test(sessions): derive lifecycle close promise from its owner
What Problem This Solves
The first chat turn recovered lifecycle timestamps through a synchronous transcript-header read. That opened a writable agent database on the Gateway thread: the measured header cohort executed 439 MAIN statements, including 346 schema/index checks.
Why This Change Was Made
Read lifecycle headers through the existing transcript reader and consume the facts under its writer FIFO, native mutation witness, and retained database owner. Migrate reply initialization, agent preparation, status rendering, and bundled Slack freshness reads together. The released synchronous SDK method remains available;
resolveSessionEntryResetFreshnessAsyncreads the entry and lifecycle facts in one snapshot.Backfill timestamps from the current patch candidate. Recheck authority after awaits, and let the existing admission controller return Stop/replacement outcomes with their original metadata. Transactions, accepted-work settlement, schemas, and stored formats retain their existing owners.
User Impact
No timestamp, reset-policy, configuration, retention, or durability change. This removes main-thread SQL from the lifecycle-header path. The coordinator accepted this as an intermediate step; the separate sharing-custody lane owns the remaining admission cutover. It does not eliminate all first-use admission: 434 statements move to the existing sharing-store caller at
src/config/sessions/session-sharing-store.async.ts:216.No new
OPENCLAW_*names.Evidence
Paired synthetic Gateway workload on an isolated 8-vCPU Hetzner host, with the unchanged sqlmeasure4 harness and per-site attribution. Base:
3b60dc8ba2c34d9de93e7385e169d92801f5c3a2; final head:6eb1c8d4ed2f5f303f45e72153e5358056f0a680. Three repetitions per revision; successful native SQL executions, not latency measurements.The remaining 434 writable-admission statements, including all 346 schema/index checks, are attributed to the existing sharing-store caller above. This is a complete cutover of the header path, with 7 fewer stable first-turn MAIN executions overall, not a removal of all first-use admission work.
Background session-registry maintenance contributes a variable 21 statements to this phase in addition to its constant 30. Both raw phase totals and the complete maintenance-excluded cohort are reported; the header cohort must not be presented as 439 total statements eliminated.
Focused runtime proof passed: 36 suites / 1,073 unique cases. The final 392-case Gateway agent suite took 99.53s wall; the remaining 26-file batch took 858.47s wall. Focused Vitest invocations used
--maxWorkers=1. The local required runtime-build-graph/import-closure group passed 12 cases in 184.94s. The importer audit covered indirect callers and previously unrouted suites; existing host-owned routing sufficed.node scripts/check-changed.mjs --base 3b60dc8ba2c34d9de93e7385e169d92801f5c3a2passed in 1,321.90s, including all core-test typecheck shards, extension types, lint, dead exports, worker/import guards, and the ratchet. Successful isolated check run.Madge: 0 cycles, 119.38s. Standalone database-worker ratchet: passed, 26.28s, then passed again inside the complete check. Final
node scripts/worktree-setup.mjs gateway: passed, 77.34s.git diff --check: clean.The pinned-base SDK API diff completed in 533.39s (successful run, digest
a109cf80). It reports 0 entrypoint additions/removals and 128 reachable-export effects from one transcript-kernel declaration: optional header selection/result fields and the kernel database parameter'sagentIdrequirement. That internal kernel does not exist inv2026.9.8; the released synchronousresolveEntryResetFreshnessruntime method retains its signature alongside the new async companion. Both revision worktrees used pinned pnpm 12.5.1. An initial parallel render exhausted host memory; the unchanged canonical tool passed using its existing serial path under four-CPU affinity.The original-path regression control fails on the intended host-SQL assertion (43.57s wall). The three worker regressions cover zero caller-thread SQL, foreign-commit freshness, unpublished synchronous SDK rewrites, and owner closure; their measured test execution totals 4.018s. New test costs are included in the focused Linux runs; GitHub CI seconds are not yet measured.
Two cancellation regressions were resolved during validation: revoked reservations initially escaped as errors, then one cached terminal reply lost
runIdmetadata. The complete 392-case Gateway suite passes after delegating outcomes to the existing admission controller. No expectations were weakened.P2 Codex autoreview: scoped-clean, no accepted/actionable findings. The released SDK compatibility path and separate persisted-turn replay migration remain explicit; no native fallback was added for failed durable worker reads.
Related/overlapping work: #165028 (shared anchor/source seam), #165205 (observer authority), #165193 (native session patches, merged while this branch was in progress), and #162433 (incidental umbrella overlap). Reply-snapshot and incognito cutovers remain separate lanes. This PR preserves minimal hunks; the later landing integrates overlapping main changes.
First landing integration (32029df)
Candidate
32029df558da6caf117c14ef1e43396af188e8f2merges mainfdd3a97f23ef55fe8e76ff8f002bcdb8cb2ffc8fwithout rebasing. The three conflicts preserve the persisted-turn replay validation from #165367 and the test cleanup from #165336 while retaining awaited command resolution. The original measurements above remain evidence for their explicitly pinned head.The released SDK check was repeated against
v2026.9.8: the JavaScript runtime freshness method keeps its synchronous signature; internal command and Gateway preparation functions are not released SDK exports. The retained method now has a compatibility-registry record, a next-Plugin-SDK-major removal gate, and a type assertion. The transcript kernel is absent from that release. Fresh P2 Codex autoreview of the integrated candidate is scoped-clean. The exact-candidate SDK API report is complete: digeste7f5c7aa, 0 entrypoint additions/removals, and 162 reachable-export effects from two additive declarations only: optional transcript header fields and the compatibility-registry record. No released signature is removed or made asynchronous.The published-driver update cell is not selected under
scripts/lib/ci-published-driver-update-plan.mtsanddocs/ci/scope-and-routing/selection.md: ordinary PRs are excluded, and these changes touch none of its updater, activation, handoff, or startup-trace owners. No schema, stored format, update driver, or migration changes are introduced.ClawSweeper completed review of
32029df558dawith no correctness or security findings and verified the conflict resolution. Its requested integration and SDK validation are recorded below. The data-model warning is a path-classification false positive:src/plugins/compat/session-persistence-records.tscontains declarative SDK deprecation metadata, and that file adds no schema, SQL, stored-data migration, backfill, or repair. Timestamp recovery still uses the existing lifecycle backfill semantics, now from the current patch candidate. The existing data and synchronous SDK contracts are preserved.Integrated-candidate proof:
pnpm test <18 focused files> --maxWorkers=1passed 18 suites / 246 cases in 3,577.22s wall on the loaded local host. This includes the replay/header/command integration, build graph/import closure, compatibility registry, and all four indirect-caller probes:status-text.model,get-reply-native-slash-fast-path.status,session.init-conflict-retry, andsession-hooks-context. No host-owner routing change was needed. The new SDK type test took 1 ms in the 20.61s three-file fast group. The integratednode scripts/worktree-setup.mjs gatewaybuild andgit diff --checkpassed.Exact-head CI run 37281014676 completed successfully on
32029df558da. All 34 selected Node test jobs passed, totaling 7,612 aggregate job-seconds (including setup, not isolated per-file cost); core and extension test typechecks passed too. No CI retry or inherited-failure admin exception was needed. The earlier PR-context metadata check was corrected by using the required problem heading.Second main integration (140df4d)
Final candidate
140df4d9b3c960f9eee09783852d1ddc8d7c7198merges mainc2e6410cd6cf9b368a369e5d53ac07f81c43c9dewithout rebasing. Main advanced during the first native merge admission; the tool rejected the resulting conflict before dispatch, with no merge request or retained merge outcome. The exact task-owned operation lock was recovered throughscripts/pr.#165360 had independently landed the same native-mutation witness. The final candidate takes main's ordered-reader implementation and its stronger revocation/cleanup tests verbatim, removing those duplicate hunks from this PR. The lifecycle helper, entry freshness implementation, transcript kernel, runtime exposure, compatibility record, and SDK type test are byte-identical to
32029df558da; the PR-owned header and compatibility declarations are unchanged. Merged main also adds an optionalPluginRuntime.gateway.resolveGitHubAccountmember, changing a declaration closure covered by the prior report. The refreshed canonical SDK diff againstc2e6410cd6cfand140df4d9b3c9completed successfully: digestf4c65373, 0 entrypoint additions/removals, and 162 reachable-export effects from the same two additive declarations. Digeste7f5c7aaremains historical evidence and is not relabeled as a new-head run.Affected proof was rerun:
pnpm test src/config/sessions/lifecycle-read.worker.test.ts src/config/sessions/session-entry-read.worker.test.ts src/config/sessions/entry-freshness.test.ts --maxWorkers=1passed 3 suites / 37 cases, 450.89s wall. Fresh full-PR P2 Codex autoreview against this main snapshot is scoped-clean. The earlier 18-suite integration proof is retained for unchanged inputs. Final-head CI 37291311417 completed successfully: 64 jobs passed and 23 were intentionally skipped; no retries or admin exception. ClawSweeper completed the final head at 09:44 UTC with no actionable correctness/security findings and explicitly confirmed that the migration warning was a metadata-path false positive.The final local SDK diff completed in 2343.90s wall, including its isolated checkout cleanup.
Final channel integration
Candidate
6ce02f9e540ad8207a2807750a44b9b417e39677merges maina1ce6fb1165d383be17b106a0d74e68446272200without rebasing. While the SDK report finished, #165436 landed its envelope-timestamp cutover, producing conflicts in the shared runtime mock and compatibility catalog. Both async helpers and both compatibility records are retained. The session-runtime mock now supplies main'sreadSessionUpdatedAtAsyncalongside this PR'sresolveEntryResetFreshnessAsync; the freshness record sits beside related session-read records instead of competing for the catalog's first position.pnpm testwith the runtime-mock, SDK freshness type, compatibility-registry, and Slack thread-context files and--maxWorkers=1passed 4 suites / 52 cases, 580.16s wall. Fresh P2 Codex autoreview against the new baseline is scoped-clean. Earlier runtime proof remains labeled with its tested revisions. The canonical local SDK report fora1ce6fb1165d..6ce02f9e540acompleted successfully, including cleanup, in 1,467.91s wall: digest37128c6e, 0 entrypoint additions/removals, and 162 reachable-export effects from two additive declarations only (optional header fields and compatibility metadata). Previous reports remain historical. Exact-head CI 37299006288 passed with 62 successful jobs and 23 intentional skips, without retries or an admin exception. ClawSweeper completed this head with no actionable correctness or security finding; the requested current-head SDK comparison is now recorded, and the compatibility-catalog metadata is not a data migration.