Skip to content

Database per repo#144

Open
davidabram wants to merge 18 commits into
mainfrom
database-per-repo
Open

Database per repo#144
davidabram wants to merge 18 commits into
mainfrom
database-per-repo

Conversation

@davidabram

Copy link
Copy Markdown
Member

No description provided.

davidabram and others added 17 commits July 17, 2026 22:21
Add config-file-only agent_trace.repository_id and
agent_trace.repository_remote keys (default remote: origin) so the
Agent Trace database can be selected per logical repository instead of
per checkout. The keys resolve with the standard global -> local merge,
are validated against the Pkl-generated JSON schema (non-empty strings,
no unknown keys), and are reported by `sce config show` in both text
and JSON with provenance.

Co-authored-by: SCE <sce@crocoder.dev>
Add a pure module at cli/src/services/repository_identity.rs that turns
an explicit configured identity or a Git remote URL into a scheme-neutral
host[:port]/path canonical form, then derives a stable repository ID as
sha256("sce-repository-id-v1\0" + canonical_identity) hex. Equivalent
SCP/ssh://HTTPS remotes converge on the same ID; credentials are stripped
and error variants carry no input fragments so they cannot leak through
diagnostics. The module performs no I/O and stays #[allow(dead_code)]
until the runtime resolver consumes it.

Co-authored-by: SCE <sce@crocoder.dev>
Move the pure repository identity module to repository_identity/mod.rs
and add a resolve submodule that applies runtime precedence: explicit
agent_trace.repository_id config first, then the configured Git
remote's URL via git config --get remote.<name>.url. The resolved
identity carries a RepositoryIdentitySource (ExplicitConfig vs
RemoteUrl) for later diagnostics, and resolution errors never echo
URLs while pointing at .sce/config.json for remediation.

Plan: repository-scoped-agent-trace-db (T03 done)

Co-authored-by: SCE <sce@crocoder.dev>
Add agent_trace_storage module resolving the active Agent Trace DB under
the invariant one logical Git repository = one database at
<state-root>/sce/repos/<repository-id>/agent-trace.db. Repository identity
comes from the explicit-config/remote-URL precedence resolver, checkout
IDs are reused for diagnostics only, and the DB opens via the same
fast-path-then-migrate pattern as the checkout resolver. Clones and
linked worktrees of the same repository share one database; legacy
checkout-scoped and global DB paths are never touched. New
default_paths::agent_trace_db_path_for_repository{,_at} helpers reject
empty or path-unsafe repository IDs. Module stays behind

Plan: repository-scoped-agent-trace-db (T04 done)

Co-authored-by: SCE <sce@crocoder.dev>
Add a repository-scoped Agent Trace DB adapter backed by one multi-statement baseline migration, seed and validate repository metadata on storage open, and run migrations with batch execution so the baseline records as one migration. Update context for the completed repository-scoped DB seam.\n\nPlan: repository-scoped-agent-trace-db\nTask: T05

Co-authored-by: SCE <sce@crocoder.dev>
Expose repository-level insert methods for diff traces, post-commit intersections, Agent Trace rows, messages, and parts, with coverage against the fresh repository schema.\n\nPlan: repository-scoped-agent-trace-db\nTask: T06

Co-authored-by: SCE <sce@crocoder.dev>
Expose repository-scoped recent diff trace queries through RepositoryAgentTraceDb and cover same-repository reads plus separate database path isolation.

Plan: repository-scoped-agent-trace-db

Task: T07

Co-authored-by: SCE <sce@crocoder.dev>
Document repository-scoped Agent Trace storage wiring across lifecycle, hook runtime, and overview context after completing T08.\n\nPlan: repository-scoped-agent-trace-db\nTask: T08

Co-authored-by: SCE <sce@crocoder.dev>
Default trace status/list/shell discovery to repository-scoped Agent Trace DBs while keeping checkout-scoped databases inspectable through --legacy. Render scope and identifier metadata in list/status outputs and refresh trace docs to match the new operator contract.

Plan: repository-scoped-agent-trace-db
Task: T09

Co-authored-by: SCE <sce@crocoder.dev>
Report repository identity source, safe canonical identity, configured remote, checkout ID, and repository-scoped database paths in trace status and related diagnostics without exposing raw remote URLs. Update context docs for the repository-scoped Agent Trace DB diagnostic contract.

Plan: repository-scoped-agent-trace-db
Task: T10

Co-authored-by: SCE <sce@crocoder.dev>
Clarify concurrent initialization, legacy inspection boundaries, default trace behavior, and no-daemon/no-migration guarantees for repository-scoped Agent Trace storage.

Plan: repository-scoped-agent-trace-db

Tasks: T11, T12, T13

Co-authored-by: SCE <sce@crocoder.dev>
Delete the dead resolve_or_create_agent_trace_db_for_checkout function
and the now-orphaned agent_trace_db_path_for_checkout path helper, along
with the imports in checkout/mod.rs that only served the dead opener.
Both symbols belonged to the legacy per-checkout Agent Trace DB surface;
active setup and hook runtime resolve repository-scoped storage instead,
so these had no code callers.

Adds the plan tracking the full legacy retirement.

Plan: retire-legacy-agent-trace-db (T01)

Co-authored-by: SCE <sce@crocoder.dev>
Remove the genuinely-dead AgentTraceDb::open_for_hooks_without_migrations
(the no-_at variant) and drop stale #[allow(dead_code)] attributes from
items now actively used by RepositoryAgentTraceDb and trace command code:
INSERT_MESSAGE_SQL, INSERT_PART_SQL, MessageRole, InsertMessageInsert,
PartType, InsertPartInsert, and the discovery types/functions.

Dropping the module-level allow on pub mod repository surfaced two
test-only methods (insert_message/insert_part) it had masked; add
per-method #[allow(dead_code)] to those so no new warnings appear.

Plan: retire-legacy-agent-trace-db (T02)

Co-authored-by: SCE <sce@crocoder.dev>
Delete the --legacy flag, LegacyCheckout discovery kind, legacy
discovery/status/shell branches, StatusError, and associated
legacy-only tests so sce trace operates only on repository-scoped DBs.

- cli_schema: drop --legacy clap args on Status/TraceDb::List/Shell
- trace/mod: remove legacy fields from TraceSubcommandRequest variants
- command_runtime + command_registry: drop legacy plumbing and the
  status-all default-false shortcut
- trace/command: remove if *legacy branches and the --legacy shell
  validation message
- discovery: remove DiscoveredAgentTraceDbKind::LegacyCheckout,
  discover_legacy_agent_trace_dbs(_in)
- status: remove StatusError, resolve_current_legacy_status_in;
  reduce StatusErrorOrRuntime to a single Runtime variant
- status_all: drop legacy parameter from aggregate_current_status_all
  and aggregate_status_all_in
- render_status: hardcode database_scope to "repository"
- render_list/render_status_all/status_all/discovery: remove legacy
  test fixtures and seeders; keep repository-schema and empty-dir tests
- shell: normalize stale ShellTarget.scope fixture to "repository"

Plan: retire-legacy-agent-trace-db
Task: T03

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

Switch the trace test seeders in stats.rs and shell.rs from the legacy
AgentTraceDb migration chain to RepositoryAgentTraceDb::new_at, and pull
the shell production open path forward onto RepositoryAgentTraceDb via a
new open_for_hooks_without_migrations_at inherent method so no test or
shell caller depends on the legacy adapter.

Drop the flaky concurrent_first_open_converges_on_one_repository_database
barrier stress test (and its now-unused Arc/Barrier import), which
exposed non-idempotent write-retry behavior under WAL contention once the
faster repository schema tightened test timing.

Plan: retire-legacy-agent-trace-db (T04 done; T05 rescoped to
stats/discovery after the shell switch was pulled forward)

Co-authored-by: SCE <sce@crocoder.dev>
Replace the legacy AgentTraceDb adapter with RepositoryAgentTraceDb in
probe_readiness (discovery.rs) and collect_agent_trace_db_stats and its
count_rows/query_optional_* helpers (stats.rs), opening via
open_for_hooks_without_migrations_at. This removes the last production
caller of the legacy AgentTraceDb type in trace read paths, leaving only
hooks log strings and the LifecycleProviderId enum variant referencing
the name.

Plan: retire-legacy-agent-trace-db (T05 done)

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

Remove the legacy AgentTraceDb type, AgentTraceDbSpec, agent_trace_db_path()
global sentinel, the AGENT_TRACE_MIGRATIONS constant, and the 15-file
cli/migrations/agent-trace/ chain. RepositoryAgentTraceDb is now the sole Agent
Trace DB adapter. The lifecycle no-repo-root path bails with an actionable
"requires a Git repository" diagnostic instead of probing the global path.

Update current-state context docs to drop the removed adapter/--legacy surface
and record the policy-reversal decision retiring the legacy checkout-scoped
Agent Trace DB.

Plan: retire-legacy-agent-trace-db T06, T07

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

Co-authored-by: SCE <sce@crocoder.dev>
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