Libra CodeHub

CedarCopilot/cedar-mail

Branch: staging

feat(drafting): one editable `drafter` system agent

merged#2624CedarCopilot

CedarCopilot wants to merge 13 commits into staging from feat/drafter-system-agent

Live on prod, no production signal yetTimeline and evidence
  1. Opened
    Aug 29, 2026, 6:16 PM
  2. Aug 31, 2026, 3:27 PM
  3. Merged
    Aug 31, 2026, 8:30 PM
  4. Live on prod
    Aug 31, 2026, 8:30 PM
  5. Observed 2 days
    Aug 31, 2026, 8:30 PM
  6. Pipelines steady after this deploy
    Aug 31, 2026, 8:30 PM
  7. Unobserved

    Live on prod, no production signal yet

    Sep 3, 2026, 7:41 PM

Behaviors Libra is checking

Operators can roll out `subagents/drafter.md` to selected existing accounts or an explicitly acknowledged full active-user cohort, with dry-run reporting by default.Degradedlow confidence

Strict CloudWatch fallback found 6 prod failure log lines for [UpdateExternalCrmWorkflow] Driver update failed (No valid values in \) in the last 24h while checking /drafter.md, reviewconversationfanout, reviewconversationtool, runsubagenttool, oneventexecutiondraftemailtool.

prod, checked Sep 3, 2026, 7:41 PM
A `<drafter_instructions>` block can impose additional skip conditions on every drafting path, and the executor records the reason without calling a draft tool when one applies.Degradedlow confidence

Strict CloudWatch fallback found 6 prod failure log lines for [UpdateExternalCrmWorkflow] Driver update failed (No valid values in \) in the last 24h while checking reviewconversationfanout, reviewconversationtool, runsubagenttool, oneventexecutiondraftemailtool.

prod, checked Sep 3, 2026, 7:41 PM
Setting `enabled: false` in `crm-updater.md` stops CRM field updates and leaves no sub-execution behind, while missing or true `enabled` values continue to run.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 2, 2026, 7:43 PM
Drafting runs load the account's `subagents/drafter.md` instructions on every execution so users can change the drafter's behavior without a code deployment.Inconclusivelow confidence

Strict CloudWatch fallback found 3 recent prod failure log lines for [UpdateExternalCrmWorkflow] Driver update failed (No valid values in \), but the same failure had 42 log lines in the comparable pre-deploy baseline. Libra is not blaming this PR intent without a post-deploy.

prod, checked Sep 2, 2026, 8:41 PM
Operators can activate the named drafter ref for pilot accounts while retiring a live `deal-drafter` ref in the same playbook update, with fleet-wide ref activation refused.Not checked
prod
Background email drafting uses `draft-email` so the generated draft creates the reviewable user task rather than only saving provider draft content.Not checked
prod

Libra has verdicts on 0 of 18 tracked behaviors on prod; 18 are still being checked. Libra has 2 low-confidence degraded verdicts it is still confirming. Libra checks hourly for 3 days after each deploy.

Introduces drafter, one editable system subagent that owns how Cedar writes a draft, replacing deal-drafter. Everything here is either inert or behind cedar-drafter-subagent (default off), except two deliberate fleet-wide changes called out below.

Design and the measurements behind every decision: docs/design/drafter-system-agent.md.

Why

Drafting was split across four harnesses and two tools, and only two of the four reliably produced a task:

pathdrafts viacreates a task
event , meetingdraft-emailyes
event , emaildraft-email or save-draftonly via draft-email
scheduled task (largest, 2,494 dispatches/14d)draft-emailyes
review (daily agenda)save-draftno

~450 background drafts a fortnight land in Gmail with no agenda card. 387 of 391 inbound response drafts, and all 66 the review path produced. One cause: the document reached save-draft because that was the only draft tool its harness had. draft-email is registered in exactly one place, as a base tool of the executor agent.

Meanwhile deal-drafter is effectively not deployed , of 56 users whose morning sweep runs, 5 have the document and 1 has a live <ref>.

What's in this PR

  • drafter replaces deal-drafter. Its body is derived line by line from the union of the executor prompt and DEAL_DRAFTER_DEFAULT_BODY, so the seed is behaviour-neutral by construction. Invariants that must not be user-editable (tool contract, taskType, threadId, TISER) are deliberately absent, and a test asserts it.
  • The seed writes the document but no ref, so a new account lands in the same state a migrated one does before activation.
  • Flag-gated document injection into the existing drafting harness, plus run-subagent('drafter') name interception.
  • The sibling-draft guard extended to draft-email / draft-slack, and made precedence-aware.
  • Trigger blocks render in authored order, and review triage can now see block prose.
  • Dry-run migration scripts for Stages 0/2/3.
  • curated-agenda-migration retired along with its tRPC route and CLI entry.

The two changes that are NOT inert

  1. Trigger-block ordering. renderTriggerBlockBody walked [all prose, then all refs]; it now walks authored order. This is a parity fix , the legacy renderer already did this , and affects 6 blocks fleet-wide (5 meeting, 1 cron), ordering only, never content.
  2. One additive orchestrator prompt paragraph, telling it to pass prose adjacent to an @subagents/ line as additionalContext. That argument has existed and been documented all along and was passed on 0 of 27,595 run-subagent calls in 14 days, because nothing rendered prose adjacent to a ref until this PR.

The sibling guard also ships flag-independently. It is conservative, but see the review note below.

Explicitly NOT in this PR

Stage 5, once every account is migrated: removing run-post-event-executor from the tool map, renaming it, naming @subagents/drafter in the pipeline order, trimming the executor prompt.

The review-path route was cut during review. It hand-built a RequestContext missing the linked-deal <output_policy> and the conversation context, and re-derived a worse playbook context than the one already in hand. Dormant, and it belongs in Phase C with a proper hand-off.

Merge and migration order

Merging this changes nothing for existing accounts beyond the two items above. The rollout is per-account and manual:

  1. Stage 0, any time: nothing to run. The updateTaskActionData label fix ships in this PR. Do NOT run cleanup-label-rules.ts , see below.
  2. Stage 2, safe fleet-wide: backfill-drafter.ts document --all --apply. Document only, no ref, dispatched by nothing.
  3. Stage 3, per account: backfill-drafter.ts ref --email X --apply and flip cedar-drafter-subagent for that user. ref --all --apply throws by design , a script cannot flip Po
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/scripts/backfill-drafter.tsno production surface mapped
  • apps/server/scripts/cleanup-label-rules.tsno production surface mapped
  • apps/server/src/cli/playbook-migrate.tsno production surface mapped
  • apps/server/src/mastra/agents/on-event-execution-agent.tsno production surface mapped
  • apps/server/src/mastra/agents/on-event-orchestrator-agent.tsno production surface mapped
  • apps/server/src/mastra/context/values.tsno production surface mapped
  • apps/server/src/mastra/skills/tasks/daily-agenda.tsno production surface mapped
  • apps/server/src/mastra/tools/agenda/__tests__/reviewConversationFanOut.test.tsno production surface mapped
  • apps/server/src/mastra/tools/agenda/reviewConversationTool.tsno production surface mapped
  • apps/server/src/mastra/tools/draft-comms/__tests__/sibling-draft-guard.test.tsno production surface mapped
  • apps/server/src/mastra/tools/draft-comms/sibling-draft-guard.tsno production surface mapped
  • apps/server/src/mastra/tools/event-execution/__tests__/crm-updater-enabled-flag.test.tsno production surface mapped
  • apps/server/src/mastra/tools/event-execution/__tests__/draft-tools-sibling-guard.test.tsno production surface mapped
  • apps/server/src/mastra/tools/event-execution/__tests__/drafter-executor-prompt.test.tsno production surface mapped
  • apps/server/src/mastra/tools/event-execution/__tests__/runSubagentTool-drafter.test.tsno production surface mapped
  • apps/server/src/mastra/tools/event-execution/onEventExecutionDraftEmailTool.tsno production surface mapped
  • apps/server/src/mastra/tools/event-execution/onEventExecutionDraftSlackTool.tsno production surface mapped
  • apps/server/src/mastra/tools/event-execution/orchestrator-dispatch-tools.tsno production surface mapped
  • apps/server/src/mastra/tools/event-execution/runSubagentTool.tsno production surface mapped
  • apps/server/src/mastra/tools/subagent-tool-allowlists.tsno production surface mapped
  • apps/server/src/mastra/workflows/event-execution/pre-execution-setup.tsno production surface mapped
  • apps/server/src/services/agenda/__tests__/review-effects.test.tsno production surface mapped
  • apps/server/src/services/agenda/__tests__/review-triage.test.tsno production surface mapped
  • apps/server/src/services/agenda/review-effects.tsno production surface mapped
  • apps/server/src/services/agenda/review-triage.tsno production surface mapped
  • apps/server/src/services/aop/__tests__/automations-service.test.tsno production surface mapped
  • apps/server/src/services/aop/automations.tsno production surface mapped
  • apps/server/src/services/aop/linked-deal-output-policy.tsno production surface mapped
  • apps/server/src/services/playbook/__tests__/curated-agenda-migration.test.tsno production surface mapped
  • apps/server/src/services/playbook/__tests__/drafter-review-dispatch.test.tsno production surface mapped
  • apps/server/src/services/playbook/__tests__/drafter-seed.test.tsno production surface mapped
  • apps/server/src/services/playbook/__tests__/golden-output-regression.test.tsno production surface mapped
  • apps/server/src/services/playbook/__tests__/playbook-renderers.test.tsno production surface mapped
  • apps/server/src/services/playbook/__tests__/resolve-playbook-context.test.tsno production surface mapped
  • apps/server/src/services/playbook/__tests__/seed-playbook.test.tsno production surface mapped
  • apps/server/src/services/playbook/agent-defaults/__tests__/agent-defaults.test.tsno production surface mapped
  • apps/server/src/services/playbook/agent-defaults/deal-drafter.tsno production surface mapped
  • apps/server/src/services/playbook/agent-defaults/drafter.tsno production surface mapped
  • apps/server/src/services/playbook/agent-defaults/index.tsno production surface mapped
  • apps/server/src/services/playbook/agent-defaults/next-steps.tsno production surface mapped
  • apps/server/src/services/playbook/backfill/__tests__/drafter-migration.test.tsno production surface mapped
  • apps/server/src/services/playbook/backfill/__tests__/label-rules-cleanup.test.tsno production surface mapped
  • apps/server/src/services/playbook/backfill/curated-agenda-migration.tsno production surface mapped
  • apps/server/src/services/playbook/backfill/deal-drafter-legacy.tsno production surface mapped
  • apps/server/src/services/playbook/backfill/drafter-migration.tsno production surface mapped
  • apps/server/src/services/playbook/backfill/label-rules-cleanup.tsno production surface mapped
  • apps/server/src/services/playbook/backfill/playbook-cohort.tsno production surface mapped
  • apps/server/src/services/playbook/backfill/prose-compare.tsno production surface mapped
  • apps/server/src/services/playbook/playbook-execution-triggers.tsno production surface mapped
  • apps/server/src/services/playbook/playbook-renderers.tsno production surface mapped
  • apps/server/src/services/playbook/resolve-playbook-context.tsno production surface mapped
  • apps/server/src/services/playbook/seed-playbook.tsno production surface mapped
  • apps/server/src/services/task-scheduling/__tests__/update-task-action-data-label.test.tsno production surface mapped
  • apps/server/src/services/task-scheduling/execution.tsno production surface mapped
  • apps/server/src/trpc/routes/admin-playbook-migration.tsno production surface mapped
  • docs/design/drafter-rollout-baseline.mdno production surface mapped
  • docs/design/drafter-system-agent.mdno production surface mapped