Skip to content

refactor(response-handles)!: keep handles in the registered store - #4964

Merged
ScriptedAlchemy merged 13 commits into
masterfrom
triage/response-handles
Nov 26, 2026
Merged

ScriptedAlchemy merged 13 commits into
masterfrom
triage/response-handles

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Refs #4448

What changes

Response handles move out of the per-project filesystem cache (root lockfile, per-response JSON envelopes, staging/rollback/tombstone publication helpers, directory-wide scans) into the registered project session store that the daemon already owns.

  • Store (tracedecay-global-db, first commit). There's a response_handles table keyed by (admitted store-shard namespace, handle), so a content digest alone grants no access to another namespace. One row holds:

    • the immutable content
    • its full SHA-256
    • exact byte and character counts
    • created_at / expires_at

    One SQLite transaction publishes, reuses or renews the whole record, and the handle is returned only after commit.

    • A different text that shares the truncated digest is refused as a typed Collision.
    • A row whose digest or text no longer matches is never served (typed CorruptRecord). An identical publication rewrites it.
    • Inventory and expiry selection use the covering (namespace, expires_at, content_bytes) index. A test asserts this with EXPLAIN QUERY PLAN.
    • Cleanup deletes expired rows in bounded batches, each its own transaction.
  • Capabilities (tracedecay-session-memory). There are now two types:

    • ResponseHandleStore: a registered lease that can publish and look up. Retrieve, feedback request handles and LSP hold it.
    • ResponseHandlePublisher: publish-only, behind a port. Render paths hold it.

    A surface with neither gets the feature-scoped handle_storage_unavailable refusal.

  • Callers. All of these now use the store:

    • MCP render and truncation
    • tracedecay_retrieve (reads only the admitted project's store; refuses typed without one)
    • feedback request handles
    • LSP context/test-run expansion handles
    • daemon maintenance (sweeps mounted registered session stores)
    • tracedecay_status inventory, reported as stored.record_count
  • CLI. The CLI renders locally but can't open the daemon-owned store. It publishes through a new internal daemon invocation, ResponseHandlePublish, routed to the project's feedback runtime store. The publish is bounded by the CLI call's own deadline, and the CLI verifies that the returned handle matches the content it rendered.

  • Deleted:

    • the filesystem cache machinery
    • StoreLayout.response_handle_root and ActiveProjectStorageV1.response_handle_root (contracts regenerated: 2 lines in sdks/typescript/src/operations.ts)
    • the unreachable "handle store busy" LockDeadline branches
    • the now-dead cg argument of handle_tool_call_with_registry_options
  • Retirement. Maintenance removes the owned retired response-handles/ directory and its lock beside the profile root and each registered project shard. A test proves unrelated store files survive.

Verification (focused Bazel, bounded fixtures, no operator data)

Target Result
//crates/tracedecay-global-db:unit_test (full) 564/564
new response-handle store tests (restart, renew, expiry, collision/corrupt, namespace isolation, bounded cleanup, covering-index plan, concurrency, revoked-authority refusal) 9/9
//crates/tracedecay-mcp:unit_test (full) 560/560
//crates/tracedecay-cli:tracedecay_unit_test (full) 460/460
//crates/tracedecay-application:unit_test (feedback/lsp/advisory filters) 258/258
//crates/tracedecay-daemon-service:unit_test (filtered) 178 + 1
//crates/tracedecay-daemon-protocol:unit_test (filtered) 41/41
//crates/tracedecay:unit_test (maintenance/invocation/dispatch/rmcp/multi_root filters) 128/128
//crates/tracedecay:mcp_suite (retrieve/protocol/truncation/active_project filters) 57/57, incl. 4 MiB multibyte multipage reconstruction and corrupt-row → typed route problem
//crates/tracedecay:storage_suite (filtered) 8/8
//crates/tracedecay:runtime_acceptance_suite (CLI transport + feedback bootstrap) real daemon: oversized files → CLI publish → multipage retrieve; refused publication → typed handle_store_failed; held-stream --json
//crates/tracedecay:unit_test (full, after the Doctor probe fix) 840/840
bazel build --config=ci --config=clippy //crates/tracedecay:all pass
rustfmt checks for every touched crate pass

Not done / open against #4448 (hence Refs, not Closes)

  • In-flight handle transition (item 6). I didn't add a read-only legacy lookup. Handles issued before upgrade (24h TTL) answer the typed, retryable handle_not_found ("re-run the original tool") instead of their content. This follows the repo's no-legacy rule, but it's a deliberate deviation from the issue text.
  • Payload I/O / lock tenure measurement on isolated large handles (acceptance). Not measured, so no speedup is claimed. The metadata-only claim rests on the EXPLAIN QUERY PLAN test.
  • Post-commit fault tests. Pre-commit refusal is covered (revoked write authority leaves no row). There's no injected post-commit fault test, because the registered engine exposes no post-commit fault hook today.
  • Paging. Retrieve still loads and verifies the whole record per page. That's correct, and digest-verified on read, but not sliced in SQL.
  • Sync bridge. Render, feedback and LSP paths are synchronous, so they publish through native_runtime::block_on. On a current-thread Tokio runtime this is a typed store failure. Production daemon and CLI runtimes are multi-thread. Tests whose responses truncate publish a handle, so they run on flavor = "multi_thread" to match production (upgrades only, no flavor downgrades). The first push missed 19 such test files; the follow-up commit converts them.
  • doctor on a project whose session store is reset-required. Fixed in this PR. doctor no longer renders a tracedecay_runtime tool reply that needs a handle. It reads the typed runtime result before any tool-output rendering, so a refused session store that mounts no handle publisher still yields the report that explains its reset state. transport_acceptance_suite covers it (stale_sessions_store_reset, stale_project_sessions_census) and passes.
  • A backward clock step makes live handles look corrupt. Lookup treats created_at > now as CorruptRecord, so if the daemon's wall clock steps backwards, handles published moments earlier fail as corrupt until the clock catches up. Nothing wrong is ever served, and republishing the same content repairs the row. Low severity, and left as is.
  • runtime_surface_acceptance::production_lsp_negotiates_and_projects_canonical_context fails locally on macOS on routed-analyzer documentSymbolProvider negotiation (line 2655). It passes on Linux CI at the same head (runtime_acceptance_suite 142/142), so it is specific to that machine and not caused by this change. The PR's LSP edits are limited to the feedback and test-run handle sources, and capability negotiation lives in tracedecay-lsp/src/capabilities.rs, which this PR does not touch.

Coordination

  • Automation lane (ac2940760c, registered run-state store) also edits crates/tracedecay-global-db/src/lib.rs and schema_stages.rs. Neither lane reserves a schema version (both use CREATE … IF NOT EXISTS in the same stage sequence). My install call sits beside native-integration, away from their anchor. Trial 3-way merges of both files are clean in either order.
  • Native SDK lane (Consolidate the Node SDK onto shared Rust client logic through a thin napi-rs binding #4226) regenerates SDK outputs. Whoever integrates second reruns pnpm --dir dashboard run contracts:generate; that lane confirmed no conflict.

🤖 Generated with Claude Code


Devin Review

ScriptedAlchemy and others added 2 commits November 24, 2026 15:40
Response-handle records now live in a `response_handles` table of the
registered store, keyed by the admitted store-shard namespace plus the
handle, so a content digest alone grants no access to another
namespace. One row keeps the immutable content, its full SHA-256,
exact byte and character counts, and creation/expiry, so one SQLite
transaction publishes, reuses, or renews the whole record and the
handle is returned only after commit. A different text that shares
the truncated digest is refused as a collision; a row whose digest or
text no longer matches is never served and is rewritten by an
identical publication.

Inventory and expiry selection are answered by the covering
`(namespace, expires_at, content_bytes)` index (asserted with EXPLAIN
QUERY PLAN), and cleanup deletes expired rows in bounded batches.
The table installs with CREATE IF NOT EXISTS in the existing schema
stage sequence, so no schema revision is reserved.

Refs #4448

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every caller now publishes and reads response handles through the
daemon-owned registered project store instead of a per-project
filesystem cache, and the cache machinery is deleted: the root writer
lock, per-response JSON envelopes, staging/rollback/tombstone
publication, and directory-wide scans.

Render paths hold a publish-only `ResponseHandlePublisher`; retrieve,
feedback request handles, and LSP expansion handles hold the registered
`ResponseHandleStore`. A route with neither answers the feature-scoped
`handle_storage_unavailable` refusal. The CLI, which renders locally
but cannot open the daemon's store, publishes through a new internal
`ResponseHandlePublish` invocation bounded by the call's own deadline
and verifies the returned handle names the content it rendered.

Maintenance sweeps mounted registered session stores and retires the
owned `response-handles/` directory and its lock. Status reports the
metadata inventory as `stored`. `StoreLayout.response_handle_root` and
`ActiveProjectStorageV1.response_handle_root` are removed (contracts
regenerated), along with the now-unreachable handle-store-busy
LockDeadline branches.

BREAKING CHANGE: handles issued by the filesystem cache are not read
after upgrade; retrieving one answers the typed, retryable
`handle_not_found`. `ActiveProjectStorageV1` drops
`response_handle_root`.

Refs #4448

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8b4a937

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ScriptedAlchemy
ScriptedAlchemy enabled auto-merge (squash) November 25, 2026 06:15
devin-ai-integration[bot]

This comment was marked as resolved.

Fence response-handle publication through writer admission and commit, use
owner time for expiry, and repair corrupt stored metadata on republish.

Await feedback and LSP storage and render synchronous tool output on the
blocking pool. Scope maintenance leases to admitted stores. Read Doctor's
full typed runtime result without depending on session-store handles.

Refresh the embedded contract bundle and add focused regression coverage.
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

ScriptedAlchemy and others added 5 commits November 25, 2026 13:35
Carry native project-open backoff through a canonical typed application
problem, including its bounded cause and measured retry delay. Preserve it
through wire/source round trips and verify the authenticated socket probe.

Regenerate the closed SDK and dashboard contract surfaces, rebuild the
embedded host server, and cover valid and malformed native SDK responses.
Response-handle records now live in a `response_handles` table of the
registered store, keyed by the admitted store-shard namespace plus the
handle, so a content digest alone grants no access to another
namespace. One row keeps the immutable content, its full SHA-256,
exact byte and character counts, and creation/expiry, so one SQLite
transaction publishes, reuses, or renews the whole record and the
handle is returned only after commit. A different text that shares
the truncated digest is refused as a collision; a row whose digest or
text no longer matches is never served and is rewritten by an
identical publication.

Inventory and expiry selection are answered by the covering
`(namespace, expires_at, content_bytes)` index (asserted with EXPLAIN
QUERY PLAN), and cleanup deletes expired rows in bounded batches.
The table installs with CREATE IF NOT EXISTS in the existing schema
stage sequence, so no schema revision is reserved.

Refs #4448

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every caller now publishes and reads response handles through the
daemon-owned registered project store instead of a per-project
filesystem cache, and the cache machinery is deleted: the root writer
lock, per-response JSON envelopes, staging/rollback/tombstone
publication, and directory-wide scans.

Render paths hold a publish-only `ResponseHandlePublisher`; retrieve,
feedback request handles, and LSP expansion handles hold the registered
`ResponseHandleStore`. A route with neither answers the feature-scoped
`handle_storage_unavailable` refusal. The CLI, which renders locally
but cannot open the daemon's store, publishes through a new internal
`ResponseHandlePublish` invocation bounded by the call's own deadline
and verifies the returned handle names the content it rendered.

Maintenance sweeps mounted registered session stores and retires the
owned `response-handles/` directory and its lock. Status reports the
metadata inventory as `stored`. `StoreLayout.response_handle_root` and
`ActiveProjectStorageV1.response_handle_root` are removed (contracts
regenerated), along with the now-unreachable handle-store-busy
LockDeadline branches.

BREAKING CHANGE: handles issued by the filesystem cache are not read
after upgrade; retrieving one answers the typed, retryable
`handle_not_found`. `ActiveProjectStorageV1` drops
`response_handle_root`.

Refs #4448

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The handle sweep held every mounted store's owner lease for the whole
maintenance tick, so a parked tick pinned idle stores against capacity
retirement. The sweep now takes its own leases and drops them when it
returns, restoring the listing's lease lifetime.

`TraceDecay` is only used under `cfg(any(test, feature = "test-transport"))`
in the MCP handler module, so its import carries the same gate; the bare
library build reported it unused.

Tests whose responses truncate publish a handle through the synchronous
store wait, which a current-thread runtime refuses. They now run on the
multi-thread flavor the daemon and CLI use, like the tests already moved.

The embedded ChatGPT server bundle is regenerated for the SDK contract
change that removed `response_handle_root`.
Use the existing report-reader readiness authority for typed runtime
requests. Preserve terminal failed/reset-required publication states and
keep ordinary telemetry available while the report mounts.

Seed MCP retrieval fixtures with captured current timestamps while
preserving exact payload, digest, pagination, expiry, and refusal checks.
devin-ai-integration[bot]

This comment was marked as resolved.

Integrate current master and the concurrently rebased response-handle history.
Preserve deadline, cancellation, async publication, Doctor readiness, and typed
backoff fixes alongside incoming runtime coverage. Keep feedback tests on the
current-thread runtime to exercise the repaired asynchronous boundary.
devin-ai-integration[bot]

This comment was marked as resolved.

Keep project-server capacity and deferred repository discovery visible to
Doctor without changing ordinary typed clients' mounting retries. Exercise
both refusals over the real typed socket and assert a single diagnostic
request, the original retry contract, and the existing actionable finding.

Integrate current master, including the validated configuration fixes.
Doctor reads the runtime report through the typed graph-tool surface,
which calls the executor's `invoke`. The single-attempt probe counted
only `invoke_controlled`, so two admission-refusal tests read zero
attempts and failed after the request had already crossed the socket.

Count the method the production path calls.
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