Repository navigation
Description
What happened
The Harbor headless AI SDK path enables the tool-result archive writer but never registers the ArchiveRead tool on the model's tool surface. When the context budget prunes a large tool result, the placeholder that replaces it explicitly instructs the model to "Call ArchiveRead with the provided ref" — but that tool does not exist in the surface.
The original result is removed from context and the model is pointed at a recovery tool it cannot call, so the content becomes unreachable.
This is a default-path defect, not a special configuration.
How to reproduce
- Run any Harbor cell on the AI SDK backend (
packages/headless/harbor/maka_agent.py→runHarborCellFromEnv). - Have the agent produce a tool result above the prune threshold (default
maxResultEstimatedTokens2048). - Observe the rewritten tool result in the request projection: it contains a
maka://archive/...ref plusreadInstructions: "Call ArchiveRead …". - Inspect the bound tool surface:
ArchiveReadis absent. The model's call falls into the unknown-tool repair path inai-sdk-backend.ts.
Why this is the default path, not an opt-in:
harbor-cell.ts:747—const outputDir = env.MAKA_OUTPUT_DIR ?? '/logs/agent', then written back into env at:751, so an output dir always resolves.harbor-cell-context-budget-env.ts:802— the archive dir falls back toMAKA_OUTPUT_DIR/tool-result-archives, soarchiveToolResultis always provided.- Both stale prune and active prune default to enabled (
harbor-cell-context-budget-env.ts:208-237).
Environment
- Maka commit:
c089c96e2 - Surface: Headless (Harbor AI SDK path)
- OS: macOS 25.5.0 / Node from repo toolchain
Logs, screenshots, or additional context
Evidence chain (all verified against current main):
| Fact | Location |
|---|---|
ArchiveRead is defined |
packages/runtime/src/archive-read-tool.ts:61 |
Its only registration site, conditional on options.archiveResources |
packages/runtime/src/builtin-tools.ts:282 |
Placeholder gains readInstructions only after a successful archive write (active path) |
packages/runtime/src/active-tool-result-prune.ts:249-263 |
| Same for the stale path | packages/runtime/src/tool-result-archive.ts:314 |
| Harbor implements the writer | packages/headless/src/harbor-cell-context-budget-env.ts:443 |
Harbor's reader is ToolResultArchiveReader (event-identity addressed, for replay hydration) — not the ToolResultArchiveResourceReader that ArchiveRead needs (ref addressed) |
packages/headless/src/harbor-cell-context-budget-env.ts:462 vs packages/runtime/src/tool-result-archive-resource.ts:28 |
headless hand-writes its tool array and never calls buildBuiltinTools |
packages/headless/src/tools.ts:94 |
Two contributing structural gaps:
assertProductBindingCatalogClean(packages/runtime/src/tool-catalog-derive.ts:190) only validatesbound ⊆ catalog. It cannot detect "the archive writer is enabled butArchiveReadis not bound".- The existing test only asserts the writer exists (
packages/headless/src/__tests__/harbor-cell.test.ts:3421) and never assertsArchiveReadis callable — the test shares the same one-directional blind spot as the implementation.
The invariant is already articulated in the codebase for the child-agent path, at packages/runtime/src/subagent-tools.ts:70-72:
Runtime recovery tools are capability-dependent and must follow a child whenever the host provides them. Otherwise a child can receive an archive placeholder that explicitly names ArchiveRead without having that tool.
Headless misses the same invariant at the top-level tool surface.
Proposed fix
- Export
buildArchiveReadToolfrom@maka/runtime— it is currently absent frompackages/runtime/src/index.tsand from the package's subpath exports, so headless cannot reach it at all. - In
harbor-cell-context-budget-env.ts, extract the existing file-read-and-verify logic at:462into a shared helper and add aToolResultArchiveResourceReaderaddressed by{artifactId, sessionId, bodySha256, originalBytes}. It must not duplicate the read path and must not synthesize aruntimeEventIdto bypass the existing checks. - Register
ArchiveReadin the headless product surface behind exactly the same gate as the writer (archive dir resolvable). - Add a round-trip test: prune produces a placeholder →
ArchiveReadreads the content back.
Not in scope: CLI's context-budget policy, and the structural consolidation tracked separately.
Activity
fix(headless): register ArchiveRead when Harbor archives tool results
fix(headless): register ArchiveRead when Harbor archives tool results (…
refactor(runtime): make the tool-result archive capability indivisible (