CedarCopilot wants to merge 2 commits into staging from fix/chat-doc-edit-bash-detour
Libra ran this behavior against the change and confirmed the check detects when it breaks.
Changed code: documentTool.schemas.ts.
Live on prod, watching, 2 days left
Libra has verdicts on 0 of 2 tracked behaviors on prod; 2 are still being checked. Libra checks hourly for 3 days after each deploy.
Zach Moskow (Concentrate) hung a chat turn twice today (2026-09-22) trying to dedupe his ~57KB email-style.md. Root cause, from the actual persisted tool-call log:
run-chat-agent-sdk.ts) read the document into Bash/Read/Write scratch files (FULL-OLD-CONTENT.md, copy1-content.md, ...) to reconstruct and diff it.write-document's patch mode with old_string/new_string spanning nearly the entire document , holding two full copies of it in context.Agent Interrupted, twice).The harness's own system prompt is why: <skill_and_subagent_usage> (surface 'harness') says "for HTML, CSS, JSON, or any code artifact: generate it with Bash/Write... then call write-document" , a real, narrow rule for code artifacts that the model was generalizing to markdown resource docs, which it was never meant to cover.
chat-agent.ts (surface 'harness' only , the surface with real Bash/file tools; 'mastra'/'mastra-families' route file ops through run-code-executor/delegate(action="code") instead, a different mechanism not covered by this investigation): one added line telling the model that editing an existing Cedar document is a write-document job, not a Bash job.writeDocumentTool.ts + documentTool.schemas.ts (the sibling document-write family tool carries the identical stale mode description and the identical latent risk on the master-families surface , not implicated in this incident, since Zach's session used write-document not document-write, but fixed for consistency rather than left as a known-live gap): reworded mode's description to explicitly steer upsert for a whole-document rewrite and warn against a patch spanning the whole document.Built two eval scripts (apps/server/.claude/skills/playbook-instruction-eval/) reproducing the real toolset + real system-prompt text against a synthetic doc shaped like Zach's (whole document duplicated, scaled to 17KB):
| Variant | Bash-detour rate (6 trials) |
|---|---|
| Baseline (today's prod prompt) | 6/6 |
Reworded mode description alone | 5/6 , confirms this alone is not the fix |
| System-prompt carve-out alone | 2/6 |
Carve-out + reworded mode together (this PR) | 0/6 |
First pass (write-document-mode-eval.ts) tested the mode reword in isolation with only write-document/read-document offered and got a null result (8/8 correct on both variants) , it wasn't giving the model the actual competing option (Bash) the real harness grants. write-document-bash-competition-eval.ts is the real test, kept alongside it as the record of why the first attempt wasn't sufficient.
Zach's actual duplicated email-style.md was already fixed directly against prod (surgical patch via writeDocumentGuarded, verified against Yjs sync + a fresh read-back) , a data fix, not a code change, so not part of this PR.
pnpm --filter @zero/server run types , cleanclaude-sonnet-5write-document without a Bash detourš¤ Generated with Claude Code
The production prompt and schema changes appear safe, but the explicit rep
Libra has not measured any production surfaces for this change yet.