Follow-up to chat#1829 (task-email pipeline, resolved 2026-07-01). Auditing task emails (skills#69) surfaced that we cannot deterministically tie a Trigger.dev run to the email it sent — the audit joins them by account + timing. This issue tracks making that link verifiable, and removing the orphaned open-agents workflow_runs table.
Decision (2026-07-01, @sweetmantech): delete the legacy open-agents artifacts — the workflow_runs/workflow_run_steps tables and the open-agents mono submodule. They've been orphaned since 2026-05-27; the verifiable-linkage goal is solved by threading a real chat_id into /api/emails (which also fixes the footer-404 link), not by reviving the table.
Goal
Given a Trigger.dev customer-prompt-task run_id, deterministically retrieve the email it produced from email_send_log (subject, body, status) — and the reverse — without account+timing heuristics. And: 100% of task emails must carry a working footer "continue on Recoup" chat link (today 0% do). The same missing chat_id blocks both. Tables involved: email_send_log (chat_id currently null), chats, and the stale workflow_runs/workflow_run_steps. Secondary: delete the stale open-agents tables and the open-agents mono submodule so the schema and repo reflect reality.
PRs (updated 2026-07-01)
| PR |
Item |
Base |
State |
| skills#69 |
recoup-internal-task-email-audit — standing task-email health audit (surfaced this gap; documents the workaround + stale-table warnings) |
main |
✅ merged 2026-07-01 — see Done |
| (no PR yet) |
Thread chat_id into POST /api/emails → deterministic run_id ↔ email + footer chat link on 100% of task emails (today 0%) |
main |
🔜 not started — primary fix |
| (no PR yet) |
Delete workflow_runs + workflow_run_steps (open-agents legacy) — drop-table migration + regen types |
main |
🔜 not started — decided 2026-07-01 |
| (no PR yet) |
Remove the open-agents codebase from the mono submodules |
main |
🔜 not started — decided 2026-07-01 |
skills#69 is independent and can merge now. The chat_id fix is the primary deliverable (it's what gets task emails to 100% footer-link coverage and verifiable run_id → email). The two deletes are cleanup, unblocked and independent.
Done
Open — verifiable linkage
Open — delete legacy open-agents artifacts (decided 2026-07-01)
Architecture notes
- ⚠️ Do NOT use
workflow_runs or scheduled_actions.last_run/next_run for run history — they are stale. workflow_runs stopped updating 2026-05-27; scheduled_actions.last_run last set 2025-10-20, next_run 2025-11-01 (not maintained by the current Trigger.dev scheduler). Run history = the Trigger.dev Management API (GET /api/v1/runs, task customer-prompt-task, tag account:<id>); activity = chats/chat_messages. (Already baked into skills#69.)
Source references
Follow-up to chat#1829 (task-email pipeline, resolved 2026-07-01). Auditing task emails (skills#69) surfaced that we cannot deterministically tie a Trigger.dev run to the email it sent — the audit joins them by account + timing. This issue tracks making that link verifiable, and removing the orphaned open-agents
workflow_runstable.Goal
Given a Trigger.dev
customer-prompt-taskrun_id, deterministically retrieve the email it produced fromemail_send_log(subject, body, status) — and the reverse — without account+timing heuristics. And: 100% of task emails must carry a working footer "continue on Recoup" chat link (today 0% do). The same missingchat_idblocks both. Tables involved:email_send_log(chat_idcurrently null),chats, and the staleworkflow_runs/workflow_run_steps. Secondary: delete the stale open-agents tables and theopen-agentsmono submodule so the schema and repo reflect reality.PRs (updated 2026-07-01)
recoup-internal-task-email-audit— standing task-email health audit (surfaced this gap; documents the workaround + stale-table warnings)mainchat_idintoPOST /api/emails→ deterministicrun_id ↔ email+ footer chat link on 100% of task emails (today 0%)mainworkflow_runs+workflow_run_steps(open-agents legacy) — drop-table migration + regen typesmainopen-agentscodebase from the mono submodulesmainDone
recoup-internal-task-email-audit(surfaced this gap).✅ Merged 2026-07-01 (squash to
main, commitc501770). The standing task-email audit; it revealed thatrun → emailcan only be matched by account + nearest timestamp (ambiguous for multi-run accounts — Apache had 2 runs), which is what this issue makes verifiable. It also documents the stale-table warnings (workflow_runs/scheduled_actions) noted below.Verified: CI green (
check_resolvable,run_resolver_eval,validate_manifests); validated on the 2026-07-01 prod run.Open — verifiable linkage
chat_idintoPOST /api/emails→ deterministicrun_id ↔ emailAND a footer chat link on 100% of task emails. (no PR yet)email_send_log.chat_idis null on every send — agents call/api/emailswithout it. One gap, two failures:chat_idis present (getEmailFooter.ts:11,24). Evidence (2026-07-01): 0 of 9 delivered task emails carried achat_id/room_id, so none had the chat link (incl. the Apache→onerpm one that surfaced this). Every email still gets the "reply to this email" footer note — just never the link.run → emailby account + nearest timestamp — ambiguous when an account fires >1 run/window (2026-07-01: Apache had 2 runs, LV8R 3). [skills#69 § 2 "join caveat"]chat_idon every/api/emailssend (via therecoup-platform-api-accessskill +recoup-platform-email-helper), soemail_send_log.chat_idis populated →email → chat → runis exact andgetEmailFooterrenders the link. (Alternative for linkage only — tagging the send with the Triggerrun_id— does not fix the footer, so it's insufficient on its own.) Prod host is already correct (getFrontendBaseUrl→chat.recoupable.dev); the preview host bug is the separate footer-404 fix from chat#1829, needed for preview correctness only.body_html_has_chat_link/chat_idpresent).run_id, one query returns the exactemail_send_logrow(s) it produced — no timing heuristic — verified on ≥2 multi-run accounts.Open — delete legacy open-agents artifacts (decided 2026-07-01)
Delete
workflow_runs+workflow_run_steps(open-agents legacy).databasemigration20260501000001_open_agents_workflow_runs.sqlfor the deprecated open-agents app; the currentrecoupable/apinever reads or writes them — the only reference is generatedtypes/database.types.ts. Last write 2026-05-27; ~90 stale rows.recoupable/database; regeneratedatabase.types.ts; confirm no remaining refs (grep workflow_runsclean outside generated types).(B) Repurpose as the run↔chat bridge.Superseded 2026-07-01 — the verifiable linkage is solved by threading a realchat_id(above), not by resurrecting an open-agents table + adding a new write path inrunAgentWorkflow.Remove the
open-agentscodebase from the mono submodules.workflow_runstable (deleted above). It lingers as submodule(s) in the monorepo (open-agents/, plus strayopen-agents-worktree//open-agents-flat-layout/copies), adding dead weight and polluting greps.git submodule deinit -f open-agents→git rm open-agents→ drop the.gitmodulesentry +.git/modules/open-agents; remove any stray worktree/flat-layout copies. (mono repo change.)open-agents*no longer appears in.gitmodules/git submodule status; the monorepo greps/builds clean without it.Architecture notes
workflow_runsorscheduled_actions.last_run/next_runfor run history — they are stale.workflow_runsstopped updating 2026-05-27;scheduled_actions.last_runlast set 2025-10-20,next_run2025-11-01 (not maintained by the current Trigger.dev scheduler). Run history = the Trigger.dev Management API (GET /api/v1/runs, taskcustomer-prompt-task, tagaccount:<id>); activity =chats/chat_messages. (Already baked into skills#69.)Source references
chat_idopen item (overlaps Fix option 1).database/supabase/migrations/20260501000001_open_agents_workflow_runs.sql;open-agents/apps/web/lib/db/schema.ts.lib/trigger/fetchTriggerRuns.ts,lib/trigger/retrieveTaskRun.ts.