Skip to content

refactor(agents): prepare watched-session prompts from worker reads - #164288

Merged
steipete merged 4 commits into
mainfrom
dbasync/ambient
Oct 3, 2026
Merged

steipete merged 4 commits into
mainfrom
dbasync/ambient

Conversation

@steipete

@steipete steipete commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Live-turn and compaction prompt preparation read ambient watch cursors and exact session titles synchronously on the Gateway thread. Bundled harnesses reached those reads through the released synchronous SDK helper.

User Impact

Prompt text and behavior stay unchanged: sorted rows, the 20-row cap, UTF-16-safe title truncation, same-agent/main-session gating, sandbox visibility, and tool hints are preserved. No schema, stored-data, retention, durability, configuration, or update migration changes are required. No new OPENCLAW_* names are introduced.

Why This Change Was Made

Prepare watch targets through the existing shared-state reader and exact titles through the session reader, then render the existing prompt section. Capture physical stores and caller authority before waits; recheck identity, watch admission, and visibility after reads and cleanup. Reset, deletion, and pruning invalidate live read admissions; watch rows and grants are not cached.

All bundled callers await prepareWatchedSessionsHarnessContext with current host authority. The released buildWatchedSessionsHarnessContext keeps its parameters and synchronous string | undefined result. Its deprecation record and migration documentation retain compatibility until an explicitly approved Plugin SDK major. The record is static compatibility metadata, not a data migration. Native provider input carriers are unchanged.

Evidence

Final head: 511f2d67bb87ac324fe25c9644adc2226631556b; tree: 1aab1208fb9ab2b6ce07bdd3ba9e619461c5a903.

  • Exact-head CI: green. The watched-session job ran all 13 cases, including byte-identical prompt prefixes and zero caller-thread SQL with a synchronous SQL-positive control (2.826 s test bodies). The fixture job passed all 11 worker-control tests (0.111 s test bodies).
  • Full released-SDK comparison: pnpm plugin-sdk:api:diff --base v2026.9.8 --head 511f2d67bb87ac324fe25c9644adc2226631556b --json <report> --summary <summary> --evidence <evidence> passed and reviewed, 231.02 s. The retained synchronous declaration is byte-identical; the async helper is additive. The retained helper's reachable classification reflects transitive type evolution since the release, not a declaration change. Report digest: d01cb84b3015bf2cb19fa9bed7dc24fca5f6f2146dd5323073ad02082d06108c.
  • Five focused files, pnpm test <files> --maxWorkers=1: 35 passed, 36.08 s wall on the exact final head. Coverage includes real worker prompt preparation, SDK types, runtime process build graph, import closure, and the repaired control fixture.
  • The final SDK and focused proof ran on Blacksmith Testbox tbx_01m40xv62s7hh7c1eps3qtj19f (allocation run). The wrapper settled with exit 0 and the exact source tree above; the lease was stopped afterward. Allocation cleanup is not a test result.
  • Independent P2 autoreview is clean for the integrated production candidate and both fixture repairs. ClawSweeper completed final-head review with no actionable code or security findings and explicitly confirmed that no stored-data migration is required.
  • Earlier production-tree proof remains recorded: 98 focused tests (64.23 s), check-changed (725.21 s), build (476.49 s), zero import cycles, database-worker ratchet, and compiled-wrapper inventory. Runtime production delta remains +319/-39; the synchronous SDK paths retain their named compatibility contract.

CI repairs and integration

Merge commit 202c8817bc45b38069a162879291d7c580854e85 integrated main 5f52ff0f863c544519ec80bbd7eeea4248bbf4d3. The only conflict was adjacent worker-access documentation additions; both were retained. Production changes merged cleanly.

CI first exposed a PR-caused fixture mismatch: the mock lacked the admission identity and read-context capture used by pruning. Five candidate runs reproduced the same four failures; five merge-base runs passed. Fix 64b6f5f295b5102e1724a12c6b9439736ab05f74 makes the fixture satisfy the actual worker-context type. All 11 tests then passed at the normal timeout (22.08 s wall). Diagnostic comparisons used one worker and a 10-second bound for blocked mock waits; committed test timeouts and assertions were unchanged.

SQLite cleanup #164271 subsequently exposed an inherited import-time mock failure. Five main c28042dade02951be3648174b7b23066ae0c4ff5 runs and five exact CI merge b8e6c2b9513d161017659331377c7480884848a0 runs reproduced it. Fix 511f2d67bb87ac324fe25c9644adc2226631556b preserves real query factories while retaining the existing forbidden SQL-call guards. The repaired three-file CI group passed 28 tests (48.43 s suite duration); targeted types passed in 6.8 s. This overlap was incidental; no production restructuring was adopted. Both fixes are test-only. No CI retry or admin bypass was used.

Move live-turn, compaction, and bundled harness watched-session preparation to the existing shared-state and exact-entry readers. Capture store identity and current disclosure authority across waits, preserving deterministic prompt bytes.

Keep the released synchronous SDK helper as deprecated third-party compatibility and require a live host assertion for its async replacement. Record the approved additive SDK surface and compiled-wrapper dependency.
@clawsweeper

clawsweeper Bot commented Oct 3, 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 scripts Repository scripts agents Agent runtime and tooling extensions: codex extensions: agentsapi size: L labels Oct 3, 2026
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 3, 2026, 9:08 AM ET / 13:08 UTC (Revision 5).

ClawSweeper review

What this changes

Moves watched-session prompt preparation into existing database workers across agent turns, compaction, and bundled harnesses while retaining the synchronous plugin helper.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR remains useful and has no supported blocking findings. The prior migration-proof concern is resolved: the introduced changes do not alter persisted data or schemas, and the released synchronous SDK contract remains intact.

Priority: P2
Reviewed head: 511f2d67bb87ac324fe25c9644adc2226631556b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent worker cutover with focused boundary coverage and preserved released SDK behavior.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: Verified repository-admin authorship exempts this PR from the external-contributor proof gate. Inspected real-worker coverage and captured Testbox results support prompt-byte preservation and rejection of revoked reads; no stored-data contract changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Verified repository-admin authorship exempts this PR from the external-contributor proof gate. Inspected real-worker coverage and captured Testbox results support prompt-byte preservation and rejection of revoked reads; no stored-data contract changes require migration proof.
Evidence reviewed 10 items Pinned introduced changes: Reviewed the merge-base-to-head introduced hunks. The supplied test merge is stale and was not used to attribute removal of current-main behavior.
Current main still needs the cutover: Fetched main still calls synchronous ambient-watch and exact session-entry readers during watched-session preparation. It does not contain this async cutover.
Disclosure revalidation: The async preparer captures physical sources, rereads current watches after title loading, checks live admission and sandbox visibility, and repeats checks after reader cleanup before returning facts.
Findings None None.
Security None None.

How this fits together

Watched-session preparation turns durable group-watch records and session titles into a bounded prompt section describing readable conversations. Agent turns, compaction, and bundled harnesses consume that section before model execution.

flowchart TD
  A[Agent turn or compaction] --> B[Session and tool visibility gates]
  B --> C[Shared-state worker reads watches]
  C --> D[Session worker reads titles]
  D --> E[Recheck authority and store identity]
  E --> F[Render bounded prompt section]
  E --> G[Reject or omit stale facts]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +280, Tests +175, Docs +27, Other +4. Total +486 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 16 319 39 +280
Tests 6 208 33 +175
Docs 2 27 0 +27
Config 0 0 0 0
Generated 0 0 0 0
Other 2 7 3 +4
Total 26 561 75 +486

Review metrics

Metric Value Why it matters
SDK contract 1 additive async helper; 1 deprecated helper retained The shipped synchronous return contract remains available while bundled callers migrate.
Production versus tests Runtime production +319/−39; tests +208/−33 Production growth implements worker preparation and disclosure revalidation, with boundary and SDK coverage.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/plugins/compat/watched-sessions.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Use the existing worker-backed readers for bundled prompt preparation while preserving deterministic prompt bytes and the documented third-party SDK compatibility window.

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

Not applicable as a behavior-preserving refactor; current-main source directly establishes the synchronous reads being moved, and the inspected suite exercises the replacement boundary.

Is this the best way to solve the issue?

Yes. Reusing the existing shared-state and session readers preserves ownership, and retaining the released synchronous helper avoids breaking third-party plugins.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded runtime improvement that removes synchronous prompt reads without changing user configuration.
  • merge-risk: 🚨 compatibility: The public SDK gains an awaited helper and deprecates a shipped helper; the existing signature and behavior are preserved and the migration window is documented.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Verified repository-admin authorship exempts this PR from the external-contributor proof gate. Inspected real-worker coverage and captured Testbox results support prompt-byte preservation and rejection of revoked reads; no stored-data contract changes require migration proof.

Evidence

What I checked:

  • Pinned introduced changes: Reviewed the merge-base-to-head introduced hunks. The supplied test merge is stale and was not used to attribute removal of current-main behavior. (511f2d67bb87)
  • Current main still needs the cutover: Fetched main still calls synchronous ambient-watch and exact session-entry readers during watched-session preparation. It does not contain this async cutover. (src/agents/watched-sessions-prompt.ts:73, 60e1aa9bdb1c)
  • Disclosure revalidation: The async preparer captures physical sources, rereads current watches after title loading, checks live admission and sandbox visibility, and repeats checks after reader cleanup before returning facts. (src/agents/watched-sessions-prompt.ts:179, 511f2d67bb87)
  • No stored-data migration: The introduced worker operation only selects existing watch rows. Reset, deletion, and pruning retain their existing writes; added tracking holds process-local read admissions. The compatibility record is static deprecation metadata, so the previous migration-proof blocker does not apply. (src/sessions/session-state-events.read.worker.ts:30, 511f2d67bb87)
  • Released SDK contract preserved: Directly inspected the v2026.9.8 helper declaration: the existing parameters and synchronous string-or-undefined return remain unchanged. The new awaited helper requires a current-authority callback; migration documentation retains the old helper until an explicitly approved SDK major. (src/plugin-sdk/agent-harness-runtime.ts:69, 511f2d67bb87)
  • Focused production-boundary coverage: Read the complete watched-session suite. It exercises real SQLite workers, compares old/new prompt bytes with a synchronous SQL-positive control, and covers caller revocation, watch reset, visibility changes, cleanup, and physical-store replacement. The captured PR body reports 98 focused tests passing on Testbox; no tests were executed during this read-only review. (src/agents/watched-sessions-prompt.test.ts:83, 511f2d67bb87)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • obviyus: 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 (4 earlier review cycles)
  • reviewed 2026-10-03T12:11:07.537Z sha 7fe637b :: blocked before merge. :: none
  • reviewed 2026-10-03T12:16:08.738Z sha 7fe637b :: blocked before merge. :: none
  • reviewed 2026-10-03T12:30:45.116Z sha 202c881 :: blocked before merge. :: none
  • reviewed 2026-10-03T12:52:39.007Z sha 64b6f5f :: blocked before merge. :: none

@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. 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. labels Oct 3, 2026
Resolve adjacent worker-access documentation additions by retaining both. Production changes merged without conflicts; the integrated ambient cutover received a clean independent P2 review.
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Model the actual worker context and read-context capture so pruning settlement tests reach the worker. The incomplete fixture reproduced four CI failures in five candidate runs; five base runs passed. All 11 repaired tests and the targeted typecheck pass, with a clean independent P2 review.
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Main's SQLite cleanup introduced import-time query-cache factories. Keep those helpers real while retaining the fixture's forbidden SQL calls. The missing-export failure reproduced five times on main and five times on the exact CI merge; all 28 tests in the repaired CI group and the targeted typecheck pass, with a clean P2 review.
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit ad3762e into main Oct 3, 2026
151 checks passed
@steipete
steipete deleted the dbasync/ambient branch October 3, 2026 13:18
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…penclaw#164288)

* refactor(agents): prepare watched-session prompts from worker reads

Move live-turn, compaction, and bundled harness watched-session preparation to the existing shared-state and exact-entry readers. Capture store identity and current disclosure authority across waits, preserving deterministic prompt bytes.

Keep the released synchronous SDK helper as deprecated third-party compatibility and require a live host assertion for its async replacement. Record the approved additive SDK surface and compiled-wrapper dependency.

* test(sessions): align worker control fixture with admissions

Model the actual worker context and read-context capture so pruning settlement tests reach the worker. The incomplete fixture reproduced four CI failures in five candidate runs; five base runs passed. All 11 repaired tests and the targeted typecheck pass, with a clean independent P2 review.

* test(sessions): preserve query factories in worker fixture

Main's SQLite cleanup introduced import-time query-cache factories. Keep those helpers real while retaining the fixture's forbidden SQL calls. The missing-export failure reproduced five times on main and five times on the exact CI merge; all 28 tests in the repaired CI group and the targeted typecheck pass, with a clean P2 review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: agentsapi extensions: codex merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L 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