Libra CodeHub

CedarCopilot/cedar-mail

Branch: staging

[2026-08-24] merging stagign to main

merged#2570CedarCopilot

CedarCopilot wants to merge 1 commit into main from staging

Not deployedTimeline and evidence
  1. Opened
    Aug 24, 2026, 3:57 PM
  2. Merged
    Aug 24, 2026, 4:08 PM
  3. Aug 24, 2026, 4:20 PM
  4. Live on staging, live on prod, observed
    Pending
  5. Not deployed

    Not deployed

    Pending

Libra has no production signal for this change yet because it has not deployed. Libra checks hourly for 3 days after each deploy.

Greptile Summary

This PR consolidates execution staleness handling, document addressing and scope resolution, and subagent identity/ownership around shared implementations.

  • Shares a 30-minute execution-staleness threshold and uses the latest execution write when suppressing duplicate event work.
  • Adds document reads by UUID and enables organization-scoped contact virtual paths.
  • Makes document metadata the canonical source of subagent agent IDs and switches field ownership to document-backed subagents.
  • Updates the subagent-ID healing script to use guarded frontmatter patches.
  • Adds regression tests and two design proposals.

Confidence Score: 4/5

The PR should not merge until existing user-scoped contact documents are migrated to the new organization scope so contact history remains readable and singular.

The new contact scope fixes future reads and writes but does not repair the known production row stored with a non-null user ID, leaving it unreachable and allowing later writes to create a second profile.

Files Needing Attention: apps/server/src/services/documents/index.ts; apps/server/src/services/documents/virtual-paths.ts

Important Files Changed

FilenameOverview
apps/server/src/services/documents/index.tsCentralizes write scoping and adds UUID-to-path resolution, but leaves known legacy contact rows outside the new canonical scope.
apps/server/src/services/documents/virtual-paths.tsAdds organization-scoped contact paths and centralizes user-scope selection across supported path prefixes.
apps/server/src/services/agent-action-queue/executions.tsAligns reactive staleness handling with the reaper and measures execution age from the latest valid write.
apps/server/src/services/playbook/reference-resolver.tsIntroduces canonical metadata-first subagent identity and returns document identity with parsed instructions.
apps/server/src/services/aop/field-ownership.tsResolves live field owners from enabled user and organization subagent documents instead of the legacy agent table.
apps/server/src/db/migrations/scripts/playbook-health/heal-subagent-agent-ids.tsValidates canonical UUIDs and replaces full-document upserts with guarded frontmatter patches.

Flowchart

rendering diagram…
Prompt To Fix All With AI
### Issue 1
apps/server/src/services/documents/index.ts:408
**Legacy contact scope remains split**

When the known contact document with a non-null `user_id` is read or updated, the new organization-scoped lookup cannot find that row, causing the existing profile to remain inaccessible and a subsequent write to create a second profile instead of updating its accumulated context.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "Merge pull request #2569 from CedarCopil..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Context used (3)

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/cron/process-stale-execution-reaper.tsno production surface mapped
  • apps/server/src/db/migrations/scripts/playbook-health/heal-subagent-agent-ids.tsno production surface mapped
  • apps/server/src/mastra/tools/document/__tests__/readDocumentTool.by-id.test.tsno production surface mapped
  • apps/server/src/mastra/tools/document/readDocumentTool.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/task/updateNextStepsAndTasksTool.tsno production surface mapped
  • apps/server/src/services/agent-action-queue/__tests__/execution-staleness.test.tsno production surface mapped
  • apps/server/src/services/agent-action-queue/executions.tsno production surface mapped
  • apps/server/src/services/aop/aop-agents.tsno production surface mapped
  • apps/server/src/services/aop/field-ownership.tsno production surface mapped
  • apps/server/src/services/crm/email-events.tsno production surface mapped
  • apps/server/src/services/crm/meeting-events.tsno production surface mapped
  • apps/server/src/services/crm/slack-events.tsno production surface mapped
  • apps/server/src/services/documents/__tests__/contact-paths.test.tsno production surface mapped
  • apps/server/src/services/documents/index.tsno production surface mapped
  • apps/server/src/services/documents/virtual-paths.tsno production surface mapped
  • apps/server/src/services/playbook/playbook-execution-triggers.tsno production surface mapped
  • apps/server/src/services/playbook/reference-resolver.tsno production surface mapped
  • apps/server/src/services/playbook/run-single-subagent.tsno production surface mapped
  • apps/server/src/services/playbook/subagents.tsno production surface mapped
  • docs/design/agent-extraction-tags-design.mdno production surface mapped
  • docs/design/vooma-lead-tracking.mdno production surface mapped