Libra CodeHub

CedarCopilot/cedar-mail

Branch: staging

Verify and revert a subagent write, from every surface

merged#2671CedarCopilot

CedarCopilot wants to merge 2 commits into staging from feat/subagent-write-verification

Live on prod, no production signal yetTimeline and evidence
  1. Opened
    Sep 3, 2026, 11:35 AM
  2. Sep 3, 2026, 5:33 PM
  3. Merged
    Sep 3, 2026, 6:55 PM
  4. Live on prod
    Sep 3, 2026, 6:55 PM
  5. Observed 2 days
    Sep 3, 2026, 6:55 PM
  6. Pipelines steady after this deploy
    Sep 3, 2026, 6:55 PM
  7. Unobserved

    Live on prod, no production signal yet

    Sep 6, 2026, 10:42 AM

Behaviors Libra is checking

An upsert targeting an existing non-empty document is rejected with instructions to patch using the entire current content as old_string, rather than leaving callers with an unusable generic prohibition.Inconclusivelow confidence

Verification reached its 130s outer budget before the verifier returned. Libra is keeping this intent verifying until the next check.

prod, checked Sep 6, 2026, 1:45 AM
Writes to ordinary non-subagent resources continue without subagent-specific frontmatter verification, so email-style and other resource documents are not rejected for lacking agent configuration.Inconclusivehigh confidence

Production telemetry since 2026-09-04T01:55:42Z contains no writeResourceGuarded, writeDocumentGuarded, or SUBAGENT_VERIFY_FAILED log events. OTEL shows 3 successful execute_tool write-document calls, but all were ordinary conversation/overview paths, not non-subagent resource.

prod, checked Sep 6, 2026, 2:43 AM
authorSubagentDoc no longer performs its own saved-document read and verification after the guarded write, relying on the centralized guard to verify every surface exactly once.Inconclusivehigh confidence

Since deploy 2026-09-04T01:55:42Z, telemetry contains no admin.subagent.author route/span, authorSubagentDoc operation, or tied guarded-write verification signal. There are 0 matching admin/author route spans and 0 matching subagent-path writes. Only 1 successful execute_tool.

prod, checked Sep 6, 2026, 2:45 AM
authorSubagentDoc rejects supplied empty or whitespace-only description and when_to_use values before writing instead of silently retaining stale configuration.Inconclusivehigh confidence

No production telemetry matching admin.subagent.author, authorSubagentDoc, or the exact validation message was found since 2026-09-04T01:55:42Z. Exact and broadened OTEL searches returned 0 matching spans, and CloudWatch returned 0 exact admin.subagent.author executions, 0.

prod, checked Sep 6, 2026, 3:43 AM
Authoring an existing agent performs a complete-document patch using the exact current content as oldString, making the replacement conditional on the author having read the current state.Inconclusivelow confidence

Verification reached its 120s wall-clock budget before a tied verdict. Libra is keeping this intent verifying until the next check.

prod, checked Sep 6, 2026, 3:45 AM
Frontmatter field edits replace values in place, flatten embedded newlines, and remove block-scalar continuation lines so the resulting header remains parseable without regex replacement corruption.Inconclusivelow confidence

Verification reached its 130s outer budget before the verifier returned. Libra is keeping this intent verifying until the next check.

prod, checked Sep 6, 2026, 4:43 AM

Libra has verdicts on 0 of 18 tracked behaviors on prod; 18 are still being checked. Libra checks hourly for 3 days after each deploy.

Phase 1 and Phase 4 of docs/design/unified-subagent-authoring-surface.md. Phase 2 (run a subagent on demand) is not here.

The asymmetry this closes

writeDocumentGuarded is the single write path for every document, from the CLI, the in-app chat agent and the external MCP. It routes by path, and the two branches did very different amounts of work:

PLAYBOOK.mdsubagents
read the saved doc backyesno
verify ityesno
revert on failureyesno

A playbook write that produced an invalid file was reverted. A subagent write that produced an invalid file was kept. verifySubagentDoc has existed the whole time , the only thing that ever ran it was cedar-cli subagent author, which is cedarAdminProcedure. A customer writing a subagent through chat or MCP got none of it, and a document no <ref> resolves reads to them as "Cedar stopped doing the thing".

What changed

1. Verify and revert on the resource path (services/playbook/guarded-write.ts). Every subagent write is now read back from Postgres, run through verifySubagentDoc, and on failure the pre-write state is restored before a SUBAGENT_VERIFY_FAILED is thrown. Mirrors writePlaybookXml, including always syncing Yjs on the revert regardless of skipYjsSync , nobody gets a success callback for an autonomous corrective write. A write that MINTED the row soft-deletes it instead of restoring it to empty, since an empty subagent row still lists as an agent with no instructions; an existing-but-empty row is restored, because a <ref id> may already point at it. Scoped to isSubagentDocPath , verifySubagentDoc asks subagent-specific questions an email-style.md cannot answer.

2. Compose the frontmatter, on upsert only (services/playbook/subagent-frontmatter.ts, new). A first write re-emits the block through composeFrontmatter , or subagentFrontmatter(slug) for a registry agent , carrying agent_id across. This is what keeps grants in the INLINE form: written as a YAML block list, parseFrontmatter ends the list at the first non-- item line, a blank line qualifies, and the key parses as an empty grant with every entry silently dropped. Never on patch or append: a body edit must not produce a header diff, and it would fight the deliberate surgical frontmatter repair.

The re-emit refuses to run whenever it would drop a key the original declared. composeFrontmatter knows the keys the system writes, not the keys a document may carry , the fleet has permissions on 21 docs (deliberately left in place), deprecated on 6, enabled on 5, default_file on 1. It is a ratchet, not a list to maintain: a key added tomorrow and not taught to the composer disables normalization for those documents instead of erasing it from them.

3. RESOURCE_EXISTS_REQUIRES_PATCH now says how to do what it refuses. The message names the safe full-replacement pattern , patch with the ENTIRE current content as old_string, which can only succeed if the writer read the current state first. Guard behaviour is unchanged: first write upsert, every write after that patch or append.

4. subagent author updates description and when_to_use on an existing agent. Both were silently ignored on an edit; only the body was replaced. Since frontmatter is what the orchestrator renders on the ref line, an agent mis-triggering because of its when_to_use could not be repaired with the tool built to repair agents. Applied one field at a time, so grants and agent_id stay byte-identical.

authorSubagentDoc's private read-back / verify / revert is removed, not left with a comment. It is the same check the write path now runs for every surface, and its create-failure branch was the only place a subagent row was hard-deleted , which change 1 now does. What is left is what the name says: composing frontmatter around a body.

Fleet impact , the go/no-go number

Read-only scan of every live subag

Show production surfaces and changed-file mapping

Production surfaces

Libra has not measured any production surfaces for this change yet.

Changed files → surfaces

  • apps/server/src/mastra/tools/document/__tests__/subagent-write-verification.test.tsno production surface mapped
  • apps/server/src/services/playbook/__tests__/author-subagent.test.tsno production surface mapped
  • apps/server/src/services/playbook/__tests__/curated-agenda-migration.test.tsno production surface mapped
  • apps/server/src/services/playbook/__tests__/guarded-write-subagent.test.tsno production surface mapped
  • apps/server/src/services/playbook/__tests__/guarded-write.test.tsno production surface mapped
  • apps/server/src/services/playbook/__tests__/subagent-frontmatter.test.tsno production surface mapped
  • apps/server/src/services/playbook/audit-subagent-docs.tsno production surface mapped
  • apps/server/src/services/playbook/author-subagent.tsno production surface mapped
  • apps/server/src/services/playbook/guarded-write.tsno production surface mapped
  • apps/server/src/services/playbook/subagent-frontmatter.tsno production surface mapped
  • apps/server/src/services/playbook/write-document-guarded.tsno production surface mapped
  • apps/server/src/subagent-admin/cli.tsno production surface mapped
  • apps/server/src/trpc/routes/admin-subagent.tsno production surface mapped