Skip to content

refactor: move Workshop authority checks off the Gateway thread - #169966

Merged
steipete merged 2 commits into
mainfrom
dbasync/workshopauth
Oct 12, 2026
Merged

steipete merged 2 commits into
mainfrom
dbasync/workshopauth

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Autonomous Workshop reviews repeatedly queried the source session's permissions, lifecycle, and accepted transcript anchor on the Gateway thread. These checks ran from the review's general liveness callback, including provider dispatch and filesystem effects; the idle scheduler triggered the review, rather than a separate authority polling timer.

User Impact

Workshop keeps its effect-time authority checks while avoiding SQL for unchanged source authority. Permission changes, reset, replacement, deletion, transcript rewrite, and membership writes invalidate the retained fact. No schema, stored-data, retention, SDK, or update behavior changes.

A benign source write can conservatively cancel a review if an unprepared liveness check runs before async refresh. A fresh effect scope can still validate an accepted anchor after later appends. This favors a safe, recoverable cancellation over weakening the provider-send guard.

Why This Change Was Made

Reuse the existing history-worker anchor operation and the Gateway's existing scoped write receipts for the logical session and transcript. The initial worker read supplies the cached authority; later effect scopes refresh it only after a relevant receipt changes. The final synchronous guard compares its retained receipt, physical source identity, and live Workshop configuration without SQLite. It stays strict outside prepared scopes too, because provider dispatch uses that callback directly.

Removed check: the repeated joined session/anchor SELECT in the Workshop liveness callback. Accepted edge case: external processes must use the Gateway or hold exclusive ownership while it is stopped; independent foreign SQLite writes are outside the single-owner contract. No new generations, handshake, worker protocol, or synchronous fallback.

Workshop's indirect MAIN SQL route is 1 → 0. Direct Workshop T1 primitives remain 0 → 0; shared session kernels retain their other callers and are not reclassified as worker-only. The existing detached validator stays available to its other owners.

Related: #169871, #169894, #169594.

Evidence

  • Local formatting, type-aware lint on both changed TypeScript files, and git diff --check: passed.
  • All eight Workshop regressions passed in the CI test job: unchanged authority without MAIN SQL, refresh after a later append, revocation during real file preparation and before the unprepared provider-dispatch assertion, membership invalidation, and refusal of subsequent actions after denial. Writes use the actual in-process session owners. The runner is substituted in these tests; provider rejection is asserted at its production callback contract, while file mutation uses the actual filesystem effect. Vitest duration 41.75s; wrapped single-file shard 79.05s. No local Vitest rerun under current proof rules.
  • Codex autoreview: two rounds, both scoped-clean at P0–P2. One live baseline/candidate SQL pair completed, with 13 turns, child-session work, cron, compaction, a separate five-minute idle window, and clean shutdown on each side. Both traces include the background review provider request and no review/fence error; there is no direct review-finished marker at the captured log level.
  • Final-head CI passed all test/type jobs, architecture/Madge, source contracts, and database worker/dialect ratchets. The only substantive failure is inherited lint in untouched src/gateway/server-methods/users-github.test.ts:679: typescript/no-unnecessary-type-arguments on createDeferredCore<void>(). The CI merge base used file blob c1c09082fa2438b05c6ae522290d013b035cc143, identical to the independently reproduced main failure at 13e0925afdba3d6fdca82f1a15d610d3c1f675d9. Main subsequently fixed that exact unnecessary type argument in 34671d49ec92; this PR does not touch the file and its merge preserves the fix. Knip was not selected by CI; its separate CPU-gated script, production, and full-tree export scans all passed with zero entries. No update cell or SDK API diff is applicable.

Scope: this removes the repeated review-authority route. A separate change-notice generation read in review-outcome.ts remains for the follow-up; the no-change live review does not exercise it. Direct T1 primitive counts therefore do not imply every Workshop caller is already asynchronous.

One pair measured base 380c115e3926 against candidate a5afb5e17930; ten warmed turns per side. This was a heavily loaded host, so timings are not performance claims.

Measurement Base Candidate
Warmed all-thread statements, median [min–max] 426.5 [377–462] 415.5 [377–563]
Warmed requests, median [min–max] 98.5 [85–110] 95.5 [85–133]
Warmed MAIN statements, median [min–max] 0 [0–0] 0 [0–1]
Idle all-thread statements/min 58.20 68.00
Idle requests/min 23.60 28.80
Idle MAIN statements/min 0.20 0.20
Whole-workload statements / requests / MAIN 11,484 / 2,088 / 2,109 11,049 / 1,973 / 1,970
Workshop statements / requests / MAIN 152 / 4 / 135 17 / 4 / 0

Workshop attribution includes worker request IDs whose transport stacks no longer contain the original caller: model context 7 SQL, transcript anchors 9 SQL across two requests, and changes list 1 SQL, unchanged on both sides. The saving is exactly 135 repeated MAIN authority SELECTs, with no additional worker request or SQL. Those baseline checks ran during cron (32) and compaction (103); neither side ran Workshop SQL during warmed turns or literal idle. The earlier idle-only rate therefore does not reproduce in this pair. Warmed mean SQL is 417.0 → 419.1 and requests 98.2 → 97.1; these raw totals include unrelated background activity.

Shared SELECT family Base/turn Candidate/turn Whole base Whole candidate
Exact-entry facts 9.3 8.8 178 164
Actor hydration 6.7 6.7 98 95
Entry-cache snapshots 0.8 0.9 29 24
Row facts 3.6 3.6 64 59
Shared row facts 1.3 1.0 29 26
Watermarks 2.2 2.2 37 36

The one candidate warmed MAIN statement is the unchanged cron session-reaper agent_deletion_journal SELECT. Its whole-run count is exactly 3 → 3: baseline first-turn/cron/idle versus candidate warm turn 7/cron/idle. Workshop MAIN remains zero. The extra warmed snapshot also comes from timer placement: memory-corpus snapshots 8 → 7, registry maintenance 0 → 1, cron reaper 0 → 1. Both maintenance owners have exactly two snapshots per whole run; total snapshots fall 29 → 24. Their relevant source hashes are identical, and this PR's authority path first runs after all warmed turns. These are displaced unchanged maintenance operations, not added checks or invalidation work.

LOC: production +57/-6, tests +67/-55, docs +19/-22; net +60 across three files.

Reuse history-worker authority facts until existing session and transcript write receipts change. Preserve strict effect-time checks for provider dispatch and skill file writes without repeated main-thread SQL.
@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 size: S labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 replaces repeated Workshop authority queries with worker-validated facts invalidated by existing session and transcript write receipts.

Example: A Workshop review checks unchanged source authority five times.

  • Before: Each check synchronously validates session authority and the accepted transcript anchor through SQLite.
  • After: Checks compare retained write receipts without SQL, refreshing authority asynchronously when a relevant receipt changes.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation has no concrete finding, but required authority-chain evidence is absent.
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: Performance · Worth it: Yes · Fix scope: Complete
User problem: Background Workshop reviews perform repeated synchronous database work on the Gateway thread.
Reason: The maintainer-authored direction removes a remaining synchronous read path using existing infrastructure and explicitly accepts recoverable conservative cancellation.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep this PR open: it addresses a remaining main-thread SQL path with a focused, owner-approved refactor; source review found no concrete introduced defect.

Priority: P2
Reviewed head: a5afb5e17930d9567af6a2cc714e604f53bb8af0

Before merge

  • Add real behavior proof - Authority-chain proof required: show the changed Workshop guard through production provider dispatch and skill-file mutation, including successful authorized effects and denial after source permissions change to read-only or the source is replaced; the current body supplies test descriptions and pending measurements rather than an executed final-effect trace, so attach redacted logs or terminal output without credentials or 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 review attention item - No concrete bypass was found, but final-effect validation of the changed authority mechanism remains unproven.
  • Resolve merge risk - Before merge, establish that retained receipt authority rejects revoked or replaced source authority at the final provider-send and skill-file mutation boundaries.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied tests do not demonstrate actual provider dispatch rejection after revocation, and no executed base-failure/head-pass result or completed runtime authority trace is supplied.
Agent review details

How this fits together

Background Workshop reviews fork completed conversation context, call a model, and update learned skill files; source-session authority guards provider dispatch and filesystem effects.

flowchart TD
  A[Completed conversation] --> B[Workshop review]
  B --> C[History worker validation]
  C --> D[Retained authority and write receipts]
  E[Session and transcript writers] --> D
  D --> F[Final authority guard]
  F --> G[Provider send or skill file mutation]
Loading

Technical review

Best possible solution:

Retain the existing worker and receipt owners while preserving current authority checks immediately before each external effect.

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

Current-main source directly shows the repeated synchronous authority query; no target code or tests were executed during this read-only review.

Is this the best way to solve the issue?

Reusing existing worker validation and write receipts is a focused solution that preserves one authority owner and explicitly records conservative cancellation behavior.

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Verify final-effect authority (recommended)
    Supply a production-path trace showing an authorized review can send and write, then showing source permission revocation or replacement prevents subsequent provider I/O and skill-file mutation.

Provenance checked

  • Workshop final authority guard and revocation tests changes intended behavior with a stated reason (1746280: The worker migration deliberately retained synchronous reflection validation because filesystem mutation needs a synchronous guard and foreign commits were not covered by the earlier witness.)
  • Joined authority and accepted-anchor validation changes intended behavior with a stated reason (83ce140: refactor(storage): reduce duplicate reads around final authority guards #167571 consolidated permission, lifecycle, and anchor checks while retaining live final authority; this PR preserves those predicates through the existing worker reader and explains the Gateway-owned writer contract.)

Testing

Proof path: in-process harness.

Security

Needs attention: No concrete bypass was found, but final-effect validation of the changed authority mechanism remains unproven.

Evidence

What I checked:

  • Introduced changes verified: The pinned merge-base-to-head diff changes only the Workshop review, its regression tests, and worker-access documentation. (src/skills/workshop/experience-review.ts:123, a5afb5e17930)
  • Current main still uses synchronous validation: The current-main liveness callback calls validateSessionTranscriptContextAnchor; the worker-access changes have not replaced this path on the inspected main. (src/skills/workshop/experience-review.ts:198, 037aa311e132)
  • Receipt invalidation uses existing owners: Scoped tokens include physical admission identity, schema revision, unscoped writes, and the selected session-key and session-ID revisions; membership and session-entry writers publish the relevant scopes. (src/infra/sqlite-database-write-receipts.ts:120, a5afb5e17930)
  • Authority snapshot accepted under retained admission: The anchor reader consumes its synchronous callback while retaining writer admission and rejects changed native mutation witnesses before installing facts. (src/config/sessions/session-transcript-anchor-read.ts, a5afb5e17930)
  • Regression coverage and its boundary: The tests use real session mutations and check unchanged skill-file bytes after revocation during preparation, but replace the review runner and invoke the provider assertion directly rather than exercising a provider send. (src/skills/workshop/experience-review.test.ts:126, a5afb5e17930)
  • Recorded owner tradeoffs: The maintainer-authored body explicitly accepts conservative cancellation after benign writes and excludes independent foreign-process SQLite writes under the existing Gateway ownership contract. (a5afb5e17930)

PR surface

Source +51, Tests +12, Docs -3. Total +60 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 57 6 +51
Tests 1 67 55 +12
Docs 1 19 22 -3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 143 83 +60

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a focused performance improvement to background Workshop reviews, with no established urgent user regression.
  • merge-risk: 🚨 security-boundary: The patch replaces a live SQLite authority read before provider and filesystem effects with retained receipt-based authority.
  • 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 showing authorized provider sends and skill writes succeed, while permission revocation or source replacement prevents subsequent 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.

Reviewed October 12, 2026, 11:14 AM ET / 15:14 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

ClawSweeper found no concrete introduced defect. The additional end-to-end provider revocation trace is retained as a follow-up under the maintainer's relaxed landing policy, rather than a request for another review.

Executed final-head CI passed all eight Workshop tests. They use real session permission/membership/lifecycle writes and real filesystem mutation, proving that revocation during file preparation prevents the write and subsequent actions remain denied. The provider-send guard is exercised through its production admission callback contract; that test does not claim to send an HTTP request. The live isolated baseline/candidate run will separately verify successful Workshop provider dispatch and finalization, and its SQL counts will be recorded in the PR body before merge.

@steipete
steipete merged commit 3302551 into main Oct 12, 2026
130 of 133 checks passed
@steipete
steipete deleted the dbasync/workshopauth branch October 12, 2026 16:45
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…claw#169966)

Reuse worker-validated session authority and scoped Gateway write receipts while preserving effect-time revocation checks. Remove repeated synchronous anchor reads without adding worker requests.

Live attribution: Workshop SQL 152 to 17, MAIN 135 to 0, requests unchanged at four. Focused CI, type/static gates, and two Codex review rounds passed; the sole inherited lint failure is fixed on main by 6db1d81.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation 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: S 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