Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

fix: default codedb context to local retrieval

Rach9d3bcc3ad05c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 39b9f5c6..c30f93ed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,9 @@ current is part of cutting a release.
## Unreleased
+- Bare `codedb context <task>` defaults to on-device retrieval. Remote
+ reranking remains an explicit opt-in and is refused under local-only
+ policy (ADR 0084, ADR 0092).
- `#794`: the tier-1 suite ratchet counts skipped Zig tests with passed
ones. `2079 passed; 1 skipped` is a 2080-test suite, not a shrink
against a 2080 baseline.
diff --git a/docs/adr/0084-codedb-context-honors-local-only.md b/docs/adr/0084-codedb-context-honors-local-only.md
index 88e902a2..b9f2f5e0 100644
--- a/docs/adr/0084-codedb-context-honors-local-only.md
+++ b/docs/adr/0084-codedb-context-honors-local-only.md
@@ -26,6 +26,7 @@ ordinary reads to codedb-pro (ADR 0040).
- Repos that forbid transmitting working data stay on local BM25/symbol/graph.
- Callers can enforce the boundary with `local_only` even when policy files
are silent.
-- Hybrid remains the default where policy does not require local-only.
+- Hybrid is opt-in (`--hybrid` / `--semantic`); bare `context` is `--local`
+ (ADR 0086). Policy still refuses those remote flags before spawn.
- Revisit only if codedb grows a stronger in-process local composer that
graff should prefer over `--local`.
diff --git a/docs/adr/0092-codedb-context-is-local-first.md b/docs/adr/0092-codedb-context-is-local-first.md
new file mode 100644
index 00000000..ca69d34a
--- /dev/null
+++ b/docs/adr/0092-codedb-context-is-local-first.md
@@ -0,0 +1,25 @@
+# 0092. Native codedb context is local-first
+
+Status: accepted 2026-09-07
+
+## Context
+
+codedb's composer defaults to hybrid advisory rerank: local BM25/symbol
+hits plus a hosted embeddings lane. A bare `codedb context <task>`
+therefore waits on a remote dependency even when the index is local.
+ADR 0084 made `--local` mandatory under repository policy; everywhere
+else graff still spawned the hybrid default.
+
+## Decision
+
+Bare `codedb context <task>` dispatches `codedb context --local`. Remote
+rerank is opt-in via `--hybrid` or `--semantic`, and those flags are
+still refused before spawn when policy or `local_only` requires
+on-device retrieval (ADR 0084).
+
+## Consequences
+
+- Typical context calls stay on-device (BM25/symbol/graph) and return
+ without waiting on embeddings.
+- A caller that wants the hosted rerank must say so.
+- codedb's own default is unchanged; graff injects `--local` at spawn.
diff --git a/docs/adr/README.md b/docs/adr/README.md
index f3908d8a..c171d046 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -101,6 +101,7 @@ record only when you need the evidence or the edge cases.
| [0088](0088-failed-children-return-partial-evidence.md) | Failed children return bounded partial evidence with error status intact, including an excerpt for workflow synthesis. |
| [0089](0089-canonical-compaction-windows-survive-recovery.md) | Preserve standalone compaction windows across pruning and resume; opaque recovery uses the server or reports failure without discarding history. |
| [0090](0090-project-constraints-require-explicit-scope.md) | Local steering stays local; durable project constraints require explicit scope and exact current-user text, while legacy unscoped records are reviewable. |
+| [0092](0092-codedb-context-is-local-first.md) | Bare `codedb context` is `--local`; `--hybrid` / `--semantic` are opt-in remote rerank (and still refused under ADR 0084 policy). |
## When to write one
diff --git a/src/codedb_local.zig b/src/codedb_local.zig
index 9ed9e12b..0f476965 100644
--- a/src/codedb_local.zig
+++ b/src/codedb_local.zig
@@ -4,9 +4,11 @@
//! hosted embeddings lane for advisory rerank. "No remote retention" is not no
//! egress. When repository policy or the per-call `local_only` argument
//! requires on-device retrieval, graff injects `context --local` before spawn
-//! and never dispatches hybrid/semantic rerank. If that boundary cannot be
-//! guaranteed, dispatch is refused. Ordinary reads stay native codedb
-//! (ADR 0040) — this is not a codedb-pro redirect.
+//! and never dispatches hybrid/semantic rerank. Bare `context <task>` is also
+//! `--local` (ADR 0086): hybrid is the slow remote-rerank path and is opt-in.
+//! If a local-only boundary cannot be guaranteed, dispatch is refused.
+//! Ordinary reads stay native codedb (ADR 0040) — this is not a codedb-pro
+//! redirect.
const std = @import("std");
const Io = std.Io;
@@ -130,19 +132,22 @@ pub fn restHasFlag(rest: []const u8, check: *const fn ([]const u8) bool) bool {
return false;
}
-/// Default `context` is hybrid (remote advisory rerank) unless `--local`.
-pub fn defaultWouldRemoteRerank(rest: []const u8) bool {
- return !restHasFlag(rest, tokenIsLocalFlag);
+/// Explicit `--hybrid` / `--semantic` opt into remote advisory rerank.
+/// Bare `context <task>` is on-device (ADR 0086).
+pub fn restAsksRemoteRerank(rest: []const u8) bool {
+ return restHasFlag(rest, tokenIsRemoteFlag);
}
pub fn planContext(required_local: bool, rest: []const u8) Plan {
- if (!required_local) {
- if (restHasFlag(rest, tokenIsLocalFlag)) return .{ .kind = .local, .inject_local = false };
+ if (restAsksRemoteRerank(rest)) {
+ if (required_local) {
+ return .{ .kind = .refuse, .inject_local = false, .refuse_reason = refuse_remote };
+ }
return .{ .kind = .remote, .inject_local = false };
}
- if (restHasFlag(rest, tokenIsRemoteFlag)) {
- return .{ .kind = .refuse, .inject_local = false, .refuse_reason = refuse_remote };
- }
+ // Default and explicit `--local`/`--no-semantic`: on-device. Inject
+ // `--local` unless the caller already passed a local flag, so codedb
+ // does not fall through to its hybrid composer (seconds of network).
return .{ .kind = .local, .inject_local = !restHasFlag(rest, tokenIsLocalFlag) };
}
@@ -218,7 +223,7 @@ test "local-only context never selects remote rerank" {
try std.testing.expectEqual(Kind.local, plan.kind);
try std.testing.expect(plan.inject_local);
try std.testing.expect(!wouldInvokeRemoteRerank(plan));
- try std.testing.expect(defaultWouldRemoteRerank(task));
+ try std.testing.expect(!restAsksRemoteRerank(task));
const argv = try contextArgv(gpa, plan, task);
defer gpa.free(argv);
@@ -273,11 +278,21 @@ test "per-call local_only and existing --local stay on-device" {
try std.testing.expectEqual(@as(usize, 1), locals);
}
-test "without local-only policy default context still allows remote rerank" {
+test "default context is local; hybrid is opt-in (ADR 0086)" {
+ const gpa = std.testing.allocator;
const plan = planContext(false, "find auth");
- try std.testing.expectEqual(Kind.remote, plan.kind);
- try std.testing.expect(wouldInvokeRemoteRerank(plan));
- try std.testing.expect(defaultWouldRemoteRerank("find auth"));
- try std.testing.expect(!defaultWouldRemoteRerank("--local find auth"));
- try std.testing.expect(!defaultWouldRemoteRerank("--no-semantic find auth"));
+ try std.testing.expectEqual(Kind.local, plan.kind);
+ try std.testing.expect(plan.inject_local);
+ try std.testing.expect(!wouldInvokeRemoteRerank(plan));
+ try std.testing.expect(!restAsksRemoteRerank("find auth"));
+ try std.testing.expect(!restAsksRemoteRerank("--local find auth"));
+ try std.testing.expect(!restAsksRemoteRerank("--no-semantic find auth"));
+ try std.testing.expect(restAsksRemoteRerank("--hybrid find auth"));
+ const argv = try contextArgv(gpa, plan, "find auth");
+ defer gpa.free(argv);
+ try std.testing.expectEqualStrings("--local", argv[2]);
+
+ const hybrid = planContext(false, "--hybrid find auth");
+ try std.testing.expectEqual(Kind.remote, hybrid.kind);
+ try std.testing.expect(wouldInvokeRemoteRerank(hybrid));
}
diff --git a/src/no_local_tools.zig b/src/no_local_tools.zig
index 1fcd3dd1..e4d8f707 100644
--- a/src/no_local_tools.zig
+++ b/src/no_local_tools.zig
@@ -128,7 +128,7 @@ pub const lean_subagent_desc = "Spawn a sidecar for a self-contained task. Child
pub const lean_bash_desc = "Run /bin/sh -c in cwd. Returns stdout, stderr, exit. Foreground still running after 15s (or timeout ms) backgrounds — bash_output(wait_ms>0) waits; do not poll.";
pub const lean_read_file_desc = "Read a UTF-8 file. Call before editing. contains=exact-key numbered lines; start_line/end_line for a window.";
pub const lean_edit_file_desc = "Replace exact text. Prefer one batched edits[] over many calls. Prefer over write_file for an existing file.";
-pub const lean_codedb_desc = "Indexed nav: context <task> · around <name> · callpath A B · list_dir <path> · status. Prefer over bash grep/find/ls.";
+pub const lean_codedb_desc = "Indexed nav: context <task> (local) · around <name> · callpath A B · list_dir <path> · status. Prefer over bash grep/find/ls.";
pub const lean_attempt_completion_desc = "Task is done. Put the final answer in result.";
fn leanCompactDesc(name: []const u8) ?[]const u8 {
diff --git a/src/schema.zig b/src/schema.zig
index 0cf13d40..361bc577 100644
--- a/src/schema.zig
+++ b/src/schema.zig
@@ -105,9 +105,9 @@ pub const base_specs = [_]ToolSpec{
.{ .name = skill_docs.tool_name, .desc = skill_docs.tool_desc, .schema = skill_docs.tool_schema },
.{
.name = "codedb",
- .desc = "Indexed code nav (github.com/justrach/codedb). ONE command — not a hop chain: context <task> · around <name> · callpath A B · list_dir <path> · status. Prefer over bash grep/find/ls. list_dir is in-process (gitignore, PathConfine; no binary). status reports codedb.snapshot. Paths stay in the cwd. context is local-only when local_only is set or repository policy forbids transmitting working data (no remote rerank).",
+ .desc = "Indexed code nav (github.com/justrach/codedb). ONE command — not a hop chain: context <task> · around <name> · callpath A B · list_dir <path> · status. Prefer over bash grep/find/ls. list_dir is in-process (gitignore, PathConfine; no binary). status reports codedb.snapshot. Paths stay in the cwd. context is on-device (`--local`) by default; pass --hybrid/--semantic only for remote advisory rerank. local_only or repository policy refuse those remote flags before spawn.",
.schema =
- \\{"type": "object", "properties": {"command": {"type": "string", "description": "One of: \"context how does auth work\", \"around codedbGuard\", \"callpath exec codedbGuard\", \"list_dir src\", \"status\"."}, "local_only": {"type": "boolean", "description": "Force on-device retrieval: dispatch `codedb context --local` with no remote rerank. Also applied automatically when repository policy requires local-only retrieval. If local-only cannot be guaranteed, the call is refused before spawn."}}, "required": ["command"]}
+ \\{"type": "object", "properties": {"command": {"type": "string", "description": "One of: \"context how does auth work\", \"around codedbGuard\", \"callpath exec codedbGuard\", \"list_dir src\", \"status\". Bare context is local (on-device); add --hybrid only if you want remote rerank."}, "local_only": {"type": "boolean", "description": "Refuse remote rerank: dispatch `codedb context --local`. Also applied automatically when repository policy requires local-only retrieval. Explicit --hybrid/--semantic under that policy is refused before spawn."}}, "required": ["command"]}
,
},
.{ .name = result_read.tool_name, .desc = result_read.tool_desc, .schema = result_read.tool_schema },
diff --git a/src/tool_schema_tests.zig b/src/tool_schema_tests.zig
index 256b5036..7366a10f 100644
--- a/src/tool_schema_tests.zig
+++ b/src/tool_schema_tests.zig
@@ -461,7 +461,8 @@ test "codedb schema exposes per-call local_only (#765)" {
for (schema.root_specs) |t| if (std.mem.eql(u8, t.name, "codedb")) {
found = true;
try std.testing.expect(std.mem.indexOf(u8, t.schema, "\"local_only\"") != null);
- try std.testing.expect(std.mem.indexOf(u8, t.schema, "no remote rerank") != null);
+ try std.testing.expect(std.mem.indexOf(u8, t.schema, "remote rerank") != null);
+ try std.testing.expect(std.mem.indexOf(u8, t.desc, "on-device") != null);
try std.testing.expect(std.mem.indexOf(u8, t.desc, "local_only") != null);
};
try std.testing.expect(found);