Repository navigation
Description
Summary
When the watchdog claims a turn from the agent's retained terminal (#2944/#2947: the backend restarted mid-turn, the agent finished and retained the result), the execution row's completed_at is the claim time, not the time the agent finished. duration_ms then includes the claim grace (180 s) plus up to one cleanup cycle (300 s). A 64-second turn is recorded as 5 m 33 s. The Execution Details page shows the contradiction on one screen: the Duration tile says 5m 32s and the transcript footer says 1m 4s.
Build: v1.0.0-rc2 (96f88f9) · Matrix row: B9 (abilityai/trinity-enterprise#847) · Env: from-source dev stack, single uvicorn worker, PostgreSQL
Steps
- Start a sync chat that takes ~60 s (
run sleep 60 and print done). - ~15 s in:
docker restart trinity-backend. - Wait for the agent to finish and for the watchdog to claim the result (
[Watchdog] result_recovered: execution … retained 266s agoin the backend log). GET /api/agents/{name}/executions/{id}and open Execution Details in the UI.
Observed
- Row:
status = success, response prefixed "Recovered by the watchdog",duration_ms = 332721,completed_at= the watchdog claim time (09:56:18Z). - The retained record on the agent:
retained_at_iso = 09:51:51Z,envelope.metadata.duration_ms = 64234; the envelope keys are exactlystatus, response, execution_log, metadata, session_id, terminal_reason— there is noexecution_time_mskey. [fixed: values from the 2026-10-12 re-run; first run was 332800 / 64010] - UI: Duration tile 5m 32s, transcript footer 1m 4s, on the same page.
- Reproduced on every watchdog-recovered turn (twice on 2026-10-11, once on 2026-10-12; +5 to +8 min each).
Expected
completed_at = the agent's retained_at (or the terminal timestamp in the record), duration_ms = the turn's real duration. The claim time can be kept as a separate field or in the activity details, but the displayed and billed duration must be the turn's.
Where (file:line at v1.0.0-rc2)
src/backend/services/cleanup_service.py:245_claim_retained_resultbuilds theExecutionResultEnvelope(line 285) from the retained record'sstatus/response/error/…/execution_time_mskeys and hands it toapply_result(line 297). The record'sretained_atis read only for the grace check (_retained_age_seconds, line 233).src/backend/services/task_execution_service.py:3120apply_result→src/backend/db/schedules/executions.py:381update_execution_status, which stampscompleted_atwith the current time (line 436,parse_iso_timestamp(utc_now_iso())) and always computesduration_ms = completed_at − started_at(line 445). [fixed: the filed body said "when the envelope carries noexecution_time_ms" — the writer never readsexecution_time_msat all; the envelope'sexecution_time_msreaches only the activitydetailsblob (task_execution_service.py:3309) and the terminal event payload (:3329), as theExecutionResultEnvelopecomment inmodels.py:2318states.]- The agent never sends
execution_time_ms: the retained envelope isresult_callback._success_envelope(docker/base-image/agent_server/services/result_callback.py:157), called fromagent_server/routers/chat.py:142(sync chat) and:328(task), and it carries the duration only asmetadata.duration_ms;agent_server/services/retained_results.py:120wraps that envelope unchanged underretained_at. [fixed: the filed body citedrouters/chat.py:184, which is the HTTP response dict, not the retained envelope.] So the claim path handsapply_resultan envelope withexecution_time_ms = None, and even a populated value would not change the row.
Suggested fix
update_execution_status needs an optional terminal timestamp (e.g. completed_at=) threaded through apply_result; _claim_retained_result passes the record's retained_at, so duration_ms = retained_at − started_at ≈ the turn (started_at is the dispatch time, retained_at the agent's finish time). Mapping metadata.duration_ms into execution_time_ms is not sufficient on its own — it only changes the activity details and the event payload. [fixed] Add a unit test that a claimed terminal's completed_at ≤ retained_at + 1 s and its duration_ms is within a few seconds of metadata.duration_ms.
Regression?
Not a regression: the watchdog claim path is new in this release. It is a fabricated duration on a recovery path, the class the release checklist for this row lists as blocking.
Activity
pavshulin commentedon Oct 12, 2026
/claim
github-actions commentedon Oct 12, 2026
Claimed by @pavshulin. Label
status-in-progressadded.Next steps:
feature/3589-<short-slug>Fixes #3589pavshulin commentedon Oct 12, 2026
PR: #3629 · agent-side follow-up: #3628
fix(watchdog): a claimed turn records the agent's finish time, not th…
pavshulin commentedon Oct 13, 2026
rechecked on rc3
15e3502c0— pass.Env: pash (PG profile). Fixer≠verifier: code = vybe's approval on PR #3629 plus the independent validation of the follow-up floor (PR #3649, APPROVE, comment 6143704643); live leg on the deployed tag = mine.
Repro (the issue's own): inter-agent hop, backend restarted 20 s into a ~120 s callee turn, callee finished orphaned → retained; watchdog claimed 211 s later.
duration_ms= 126576 — the real wall clock, NOT claim-time inflated (the F16 defect would have stamped ~337 s).completed_at= the retained instant (13:55:25.626783Z; watchdog log "retained 211s ago" agrees).agent_collaborationclosed withcompleted_atbyte-identical to the row.fix(execution): a terminal completed_at is floored at the row's own s…
fix(activities): close cancelled-event and claimed-turn companion act…