Skip to content

remove tokio db runtimes - #301

Merged
davidabram merged 68 commits into
mainfrom
remove-tokio-db-runtimes
Oct 11, 2026
Merged

davidabram merged 68 commits into
mainfrom
remove-tokio-db-runtimes

Conversation

@davidabram

Copy link
Copy Markdown
Member

No description provided.

@davidabram
davidabram added this pull request to stack #302 October 7, 2026 13:39
@davidabram
davidabram force-pushed the remove-tokio-db-runtimes branch 2 times, most recently from 075be01 to f8e9c74 Compare October 8, 2026 13:00
@davidabram
davidabram removed this pull request from stack #302 October 10, 2026 08:24
@davidabram
davidabram added this pull request to stack #312 October 10, 2026 08:24
@davidabram
davidabram removed this pull request from stack #312 October 10, 2026 22:50
@davidabram
davidabram added this pull request to stack #324 October 11, 2026 14:45
Base automatically changed from single-tokio-runtime to main October 11, 2026 14:48
davidabram and others added 22 commits October 11, 2026 16:48
Document the compile-safe PR2 migration from synchronous Turso runtime bridging to awaited persistence on the application-owned Tokio runtime. Capture the required caller propagation, preserved transaction/retry/migration behavior, cancellation and contention regressions, cleanup boundaries, and revised PR staging without implementing the change.
Plan: cli-async-turso-persistence-pr2; tasks T01-T05.

Co-authored-by: SCE <sce@crocoder.dev>
Co-authored-by: SCE <sce@crocoder.dev>
Capture the source-grounded inventory required before replacing the Turso runtime bridge with awaited persistence. Record the affected caller and seam closure, unchanged retry/WAL/migration policies, dependency cancellation constraints, and verification map for the follow-up migration work.

Ref: context/plans/cli-async-turso-persistence-pr2.md#T01

Co-authored-by: SCE <sce@crocoder.dev>
Remove database-owned Tokio runtime bridges and propagate native async Turso operations through CLI services, credentials, lifecycle providers, hooks, mutation tracing, sync/export, and command dispatch. Preserve SQL, migrations, encryption, WAL, retry policies, and output behavior while restoring synchronous pure parsing and filesystem helpers.

Record the verification boundary: production build, compile-only test target, Quint MBT, formatting, and diff checks passed; ordinary behavioral suites remain disabled after async migration failures.

Plan: cli-async-turso-persistence-pr2.md (T02)

Co-authored-by: SCE <sce@crocoder.dev>
Delete the repository-wide `#[cfg(any())]` test modules and the production hooks, database counters, storage seams, and helper exports that existed solely to support them. Keep the active CLI implementations while removing dead code across agent-trace, hook, mutation-trace, and sync services.

Co-authored-by: SCE <sce@crocoder.dev>
Avoid unnecessary async suspension when converting transaction parameters, while moving filesystem-backed encryption-key resolution onto a blocking worker. Simplify the retry connection closure to match the synchronous setup path.

Co-authored-by: SCE <sce@crocoder.dev>
Keep Turso and database work on the application Tokio runtime while isolating only synchronous credential-store and advisory-lock polling boundaries in `spawn_blocking`. Return owned lock guards to async callers and preserve timeout, polling, and contention semantics across hook and mutation-trace integrations.

Remove obsolete async-bridge seams and orphaned ordinary Rust tests now that production callers and remaining verification are aligned; retain Quint MBT coverage. Update architecture, patterns, and plan records with the boundary and verification decisions.

Ref: context/plans/cli-async-turso-persistence-pr2.md

Co-authored-by: SCE <sce@crocoder.dev>
The guarded-shell supervisor performs blocking process and pipe polling, so running it on a Tokio worker can stall unrelated async tasks. Run supervision in spawn_blocking, forward events through a bounded channel, and preserve cancellation and cleanup/error handling across the worker boundary. Add regression coverage for runtime responsiveness and streamed output/exit handling.

Co-authored-by: SCE <sce@crocoder.dev>
Replace blocking Git subprocess calls in mutation-trace runtime and hook ingress paths with Tokio process operations. Propagate async checkout and snapshot resolution through attribution, reconciliation, doctor checks, and hook lifecycle seams.

This keeps Git-backed runtime work from blocking async executors while preserving fail-closed behavior and adding async snapshot and worktree identity coverage.

Co-authored-by: SCE <sce@crocoder.dev>
Run blocking adapter-state reads, lock acquisition, and durable writes in spawn_blocking workers so hook and doctor futures do not block Tokio threads. Apply a shared locked transaction helper across Claude, Codex, OpenCode, and Pi adapters, and add cancellation and responsiveness coverage for Claude state persistence.

Co-authored-by: SCE <sce@crocoder.dev>
Exercise agent trace reconstruction across incremental and evidence-based histories, and verify Claude structured patch derivation against fixture outputs. Keep fixture discovery explicit so missing or unexpected scenarios fail deterministically.
Previously, the three-stream join returned on the first error, dropping in-flight sibling futures and potentially interrupting credential persistence. Drive all started streams to terminal completion, retain the first observed error, and report it only after all streams finish. Document the behavior and add a regression test.

Co-authored-by: SCE <sce@crocoder.dev>
Prevent task cancellation from releasing the worktree lock while a blocking Git ref mutation is still running. Pass cloneable lock leases into the blocking worker and keep Git ref updates and deletions serialized until their subprocesses complete, while making read-only Git commands cancellable.

This closes the cancellation race around snapshot pinning and stale-pin reconciliation without changing the protected worktree ownership model.

Co-authored-by: SCE <sce@crocoder.dev>
Prevent cancellation from releasing the worktree lock while external-taint marker I/O is still in flight. Move marker arming and completion into blocking workers that own the lock for their full duration, surface worker failures, and add regressions for cancellation ordering and Tokio progress. Document the ownership boundaries and safety behavior.

Co-authored-by: SCE <sce@crocoder.dev>
Temporary index cleanup currently uses synchronous filesystem operations on async
runtime paths, and a dropped guard can perform blocking deletion on a Tokio
worker. Use Tokio filesystem APIs for setup, root resolution, and normal cleanup,
while scheduling Drop cleanup through spawn_blocking when a runtime is active.
Add coverage for cleanup timing, index preservation, and error cleanup behavior.

Co-authored-by: SCE <sce@crocoder.dev>
Reconcile the PR2 plan with the implemented async Git, filesystem, cancellation, and lifecycle work instead of retaining stale scope claims. Add focused safety criteria for transaction isolation, credential persistence, terminal sync behavior, adapter boundaries, descriptor inheritance, and deferred PR3 cleanup while documenting verification limits and ownership.
Plan: cli-async-turso-persistence-pr2 (T02, T03, T04, T05, T06, T07)

Co-authored-by: SCE <sce@crocoder.dev>
Prevent concurrent operations and cancellation from violating atomic writes by holding an exclusive mutable borrow across Turso transactions.

Use checked `Transaction::new` with `&mut Connection`, adapt retry operations to native-async traits, and propagate mutable ownership through Agent Trace, mutation-trace, and hook callers. Add contention and abandoned-transaction tests covering whole-transaction retries, bounded failure, deferred rollback, and durable row-pair behavior.

Ref: context/plans/cli-async-turso-persistence-pr2.md (T03)

Co-authored-by: SCE <sce@crocoder.dev>
…rminal failure

Prevent caller cancellation from dropping a rotated refresh token by moving renewal and persistence into an owned task that holds the single-flight guard. Share terminal state among concurrent streams so sibling reads stop after a terminal failure while an in-flight batch completes.

Plan: cli-async-turso-persistence-pr2, T06

Co-authored-by: SCE <sce@crocoder.dev>
Keep the adapter boundary lock leased by started blocking state transitions so a cancelled caller cannot be overtaken by a later boundary. Create guarded-shell descriptors close-on-exec and clear them only in the intended child, preventing unrelated subprocesses from inheriting the guard protocol.

Plan: cli-async-turso-persistence-pr2.md, T07

Co-authored-by: SCE <sce@crocoder.dev>
Mark T04 complete for cli-async-turso-persistence-pr2 after auditing the absence of obsolete DB runtime bridges and SyncStorageGuard. Record the retained synchronous blocking sites, cancellation ownership, held resources, shutdown behavior, and verification evidence for T05's architecture enumeration.
Plan: cli-async-turso-persistence-pr2 (T04)

Co-authored-by: SCE <sce@crocoder.dev>
davidabram and others added 28 commits October 11, 2026 16:48
Add explicit reconciliation and hook advisory entrypoints that share one held worktree lock, persist bounded maintenance state, and record successful and failed passes. Add verified-existing agent-trace DB opening so maintenance does not create or migrate databases, while preserving the existing deletion path.

Plan: `mutation-cursor-ref-reconciliation-wiring.md` (T02)

Co-authored-by: SCE <sce@crocoder.dev>
Ensure explicit reconciliation uses the production-resolved, verified read-only database and reports state-persistence diagnostics without losing reconciliation errors. Distinguish pre-rename failures from post-rename durability uncertainty, require confirmed writes for advisory results, and add deterministic coverage for open races, WAL coexistence, lock ownership, and persistence failures.

Plan: mutation-cursor-ref-reconciliation-wiring (T02)

Co-authored-by: SCE <sce@crocoder.dev>
…scopes

Completed mutation-scope boundaries now run the advisory-only ref reconciliation check after coordination returns, while preserving hook results and avoiding reconciliation, Git, or database work on the hook path. The injected report is mapped to stable debug or warning logs, including durability and state failures, and is limited to Close and Flush boundaries.

Ref: context/plans/mutation-cursor-ref-reconciliation-wiring.md (T03)

Co-authored-by: SCE <sce@crocoder.dev>
Expose actionable reconciliation advisory outcomes through an injected diagnostic writer while retaining structured logging. Add outcome-specific diagnostics for durability and state-write failures, keep advisory delivery independent of mutation results, and cover the seven outcome shapes with focused tests.

Ref: context/plans/mutation-cursor-ref-reconciliation-wiring.md (T03)

Co-authored-by: SCE <sce@crocoder.dev>
Make `sce doctor --fix` execute one explicit snapshot-ref reconciliation pass and report typed outcomes, while plain `sce doctor` remains read-only and reports when maintenance is recommended. Add a runtime facade and injected seams to preserve doctor testability and expose counts, failure kinds, warnings, and busy results.

Update the `mutation-cursor-ref-reconciliation-wiring` plan and related context for T04.

Co-authored-by: SCE <sce@crocoder.dev>
Cover retention of durable roots across worktrees, fail-closed handling of malformed namespace refs, and advisory busy behavior while an explicit pass holds the lock. Parameterize the durable-root fixture so the production-path tests exercise foreign worktree roots without repairing missing pins.

Plan: mutation-cursor-ref-reconciliation-wiring (T05)

Co-authored-by: SCE <sce@crocoder.dev>
Add CLI, linked-worktree, cross-process, lock-contention, state-recovery, and cancellation tests for the ref reconciliation path, using narrow coordinator and snapshot seams to exercise real behavior without changing production semantics. Cover database verification and fail-closed behavior, durable state normalization and uncertain persistence, hook/advisory ordering, and doctor outcomes.

Plan: mutation-cursor-ref-reconciliation-wiring.md (T05)
T05 remains in progress for the explicitly recorded S9, S14, and S26 production-path gaps and guard-removal checks.

Co-authored-by: SCE <sce@crocoder.dev>
Remove obsolete dead-code allowances now that snapshot-ref reconciliation runs through `sce doctor --fix`, keep only justified single-event loader exceptions, and make unreachable checkout-identity outcomes and test-only wrappers explicit. Synchronize the reconciliation, doctor, storage, and overview context with the single-lock maintenance entrypoint, verified-existing DB contract, advisory boundary, typed outcomes, and deferred cleanup limitations.

Plan: `context/plans/mutation-cursor-ref-reconciliation-wiring.md` — T06

Co-authored-by: SCE <sce@crocoder.dev>
Expand doctor CLI coverage to assert successful exit status for reported reconciliation outcomes and to exercise recovery from failed, stale, invalid, corrupt, oversized, and unreadable maintenance state. Record the remediation evidence and completed coverage status for the reconciliation wiring plan.

Plan: mutation-cursor-ref-reconciliation-wiring (T05)

Co-authored-by: SCE <sce@crocoder.dev>
Preserve the persistence failure phase when advisory anchor or normalization writes complete replacement but cannot confirm directory durability. Render a durability-specific diagnostic for those outcomes, while retaining the existing write-failed wording for pre-rename failures and adding regression coverage for visible post-rename state.

Update the reconciliation plan's T05 durability semantics and scenario coverage to match the outcome mapping.
Plan: mutation-cursor-ref-reconciliation-wiring (T05)

Co-authored-by: SCE <sce@crocoder.dev>
Add regression coverage proving that maintenance opening of a missing Agent Trace database returns the typed missing-database error without creating state-root entries. Mark the mutation-cursor reconciliation plan's acceptance criteria complete and record validation evidence for the completed implementation.

Plan: mutation-cursor-ref-reconciliation-wiring
Tasks: T05, T06

Co-authored-by: SCE <sce@crocoder.dev>
The doctor reconciliation CLI test sandbox assumed a `state` directory under the temporary home, but on macOS the CLI resolves its state root to `Library/Application Support`. Resolve the sandbox state root per platform so the tests locate the same Agent Trace database and maintenance state as the CLI under test.

Co-authored-by: SCE <sce@crocoder.dev>
Consolidate redundant reconciliation, advisory, doctor, and maintenance-state tests into table-driven cases while strengthening assertions for exit statuses, ref inventories, pin preservation, typed failures, and read-only database behavior. Remove obsolete test-only lock-acquisition wrappers and align the CLI/context coverage documentation with the retained scenarios.

Plan: mutation-cursor-ref-reconciliation-wiring
Tasks: T05

Co-authored-by: SCE <sce@crocoder.dev>
Allow a retry when its backoff can finish before the contention deadline without requiring the busy timeout to fit in the remaining budget. Add boundary tests covering sleep and immediate retry eligibility.

Co-authored-by: SCE <sce@crocoder.dev>
Interactive setup previously offered a single-choice target prompt with an
"All" option, re-asked every confirmation on each run, and always merged the
chosen target into the persisted target list, so deselecting a target was
impossible.

Introduce ConcreteSetupTarget so install, repair, and asset iteration
operate on real targets only, removing the unreachable "All" branches. The
interactive prompt is now a validated multi-select pre-filled from the
targets persisted in .sce/config.json, and previously stored agent-trace
auto-sync and attribution-hooks answers are reused instead of prompting
again. Interactive runs replace the persisted target list, while
non-interactive flag runs keep merging. CLI target flags collapse into a
single optional SetupTarget, and auth DB setup skips initialization when
the database already exists.

Co-authored-by: SCE <sce@crocoder.dev>
Cover two concurrent trace-sync termination scenarios that were not
exercised before.

The first test runs three streams where the messages stream fails with
Forbidden while a sibling stream also fails with AuthenticationFailed
and a third stream still has backlog. It asserts that the first
terminal error is reported and that neither sibling reads or ingests
past its in-flight batch once termination is signalled.

The second test lets a sibling batch fail ambiguously with a server
error after termination, using a counting empty credential store. It
asserts that the first Forbidden error is kept, the sibling stops after
its in-flight batch, and credential state is loaded exactly once.

Co-authored-by: SCE <sce@crocoder.dev>
Apply a one-minute timeout to ingestion batch requests so stalled requests
and response bodies cannot indefinitely delay sync completion. Classify
response-body timeouts as transport failures for cursor reconciliation.

Add scripted HTTP regressions for stalled requests and bodies, retrying
uncommitted batches, reconciling committed batches without resending, and
reporting terminal failures after a sibling batch times out. Remove the
standalone test HTTP server helper.

Co-authored-by: SCE <sce@crocoder.dev>
@davidabram
davidabram force-pushed the remove-tokio-db-runtimes branch from cc63f47 to f3c3525 Compare October 11, 2026 14:48
@davidabram
davidabram merged commit 82e2eb5 into main Oct 11, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant