Repository navigation
fix(execution): a terminal completed_at is floored at the row's own started_at (trinity-enterprise#882) - #3649
Conversation
…tarted_at (trinity-enterprise#882) #3629 made the producer's terminal instant authoritative; terminal_completed_at clamped only the future, so a past value reached the completed_at column verbatim. The helper gains a REQUIRED keyword-only floor: parameter — the fourth rule in the one place both writers resolve through — and update_execution_status / complete_activity pass the row's own server-written started_at. A floored write logs a warning and remains a successful claim; an in-window instant (the #3589 behaviour) is recorded verbatim; the future-clamp is unchanged; a naive floor is normalized to UTC like the given instant. TDD: 10 of the 15 new tests in tests/unit/test_882_completed_at_floor.py were red before the fix — the column assertion failed with the backdated value written verbatim. test_3589_claim_completed_at.py stays green (37/37; four direct helper calls updated to the new signature, assertions unchanged). test_1482_write_params.py's persistence fixture moves to an in-window instant. Fixes abilityai/trinity-enterprise#882 Co-Authored-By: Claude Fable 5 <[email protected]>
Independent validation — APPROVE ✅Validated per the ent#882 validator handoff, in an isolated worktree at head The hole is closed (the deciding check). Hostile-envelope trace: a backdated Both writers, both floors — and the activity close floors at the activity row's own #3589 preserved, and provably distinct from an overwrite. In-window values land verbatim, pinned column-level in both writer suites. Caller sweep: exactly two production call sites, both floored; no caller in the scheduler or agent-server trees; the required keyword-only Tests + mutations (fresh py3.13 venv; SQLite — no PG env on this machine):
Floor fires loudly: the warning names the delta in seconds — the audit signal is there. Scope + hygiene: exactly the brief (2 writers + helper + tests + the tiered docs); no disclosure concerns — class described, no recipe. Notes for the merger: Tier-1 Full report: 🤖 Generated with Claude Code |
dolho
left a comment
There was a problem hiding this comment.
/review on 35a76c684: approve. This is the independent validation the body asks for.
Scope: clean. One rule added in the one helper both terminal writers resolve through (terminal_completed_at), and both writers pass the row's own started_at. A grep finds no other caller of the helper under src/ or docker/, so the required keyword-only floor can't be skipped by a third writer today, and won't be tomorrow (see M5).
Logic:
- Order is right. The future-clamp applies first, then the floor. On skew (
started_atahead of our clock) the floor wins, which is the invariant retention reads ("cannot end before it starts"). Duration is 0 either way. - A naive
flooris treated as UTC, the same asgiven, so the terminal path never raises on mixed naive and aware values. - A floored write is still a claim: the status stays terminal and only the instant moves. In-window
[started_at, now]values are recorded verbatim, so #3589's behaviour is unchanged. - Both floors are server-written:
schedule_executions.started_at/agent_activities.started_at, read back from the row inside the writer (parse_iso_timestamp(row["started_at"])). Never the envelope.
Validation: hostile envelope traced to the column, and hand mutations
The 52-test battery is green locally, 71 including test_1482_write_params. test_882 asserts on the completed_at column through the real DB (db_harness), not on the helper's return value, which is the trace the handoff asked for.
| Mutation | Red |
|---|---|
| M1: floor rule disabled in the helper | 6 |
M2: update_execution_status passes floor=None (floor-vs-overwrite, executions) |
2 |
M3: complete_activity passes floor=None (activities) |
1 |
| M4: clamp re-applied after the floor (clamp wins on skew) | 1 |
M5: floor made optional (= None default), so a third writer could skip it silently |
1 |
Every arm has a test that fails without it.
Informational (non-blocking)
- A floored skewed row can carry a future
completed_at(confidence 5/10, low): whenstarted_atis ahead of our clock, the floor deliberately wins over the clamp, socompleted_at= that futurestarted_at. That delays pruning; it never hastens it, which is the safe direction for this issue. Readers that comparecompleted_atagainst "now" (a "finished N ago" label) could briefly read slightly odd. Stated in the docstring, so this is just for the record. - Log wording: both warnings carry the
[#3589]tag. The floor's line would be easier to find under[ent#882]. Cosmetic.
CI: 18 passed, 2 pending at review time. It's still a draft with "DO NOT MERGE — independent validation pending" in the body: from my side validation is done, so it's yours to mark ready and drop the banner once CI lands.
🤖 Generated with Claude Code
tests/registry.json: keep both appended entries (trinity-enterprise#882 and #3588). tests/unit/test_3588_close_cancelled_claimed_activities.py: seed execution and activity start times before the fixed instant _T. A terminal completed_at is floored at the row's own started_at (trinity-enterprise#882, PR #3649), so rows seeded at "now" had the past instant raised to their start and three timestamp-agreement assertions failed on the merged tree. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
completed_atcan no longer precede the row's ownstarted_at: a turn cannot end before it starts. fix(watchdog): a claimed turn records the agent's finish time, not the claim time (abilityai/trinity#3589) #3629 made the producer's terminal instant authoritative; this floors it at the server-written start, in the one helper both writers resolve through.terminal_completed_atgains a REQUIRED keyword-onlyfloor:parameter (the fourth rule, same home as the other three), and both terminal writers (update_execution_status,complete_activity) pass the row's ownstarted_at. A floored write logs a warning and remains a successful claim — never a refusal.[started_at, now]is recorded verbatim; the future-clamp is unchanged.Changes
src/backend/utils/helpers.py— the floor rule interminal_completed_at; required keyword-only so a future third writer must decide, never silently skip; naivefloornormalized to UTC likegiven.src/backend/db/schedules/executions.py,src/backend/db/activities.py— both writers passfloor=started_at.tests/unit/test_882_completed_at_floor.py— 15 tests: the backdated envelope lands in thecompleted_atCOLUMN asstarted_at(column-level assertion) withduration_ms == 0and the status still terminal, on both tables, real DB viadb_harness(PG leg underTEST_POSTGRES_URL); in-window verbatim; future-clamp regression pins; floor-vs-clamp precedence on skew; the required-parameter pin.tests/unit/test_3589_claim_completed_at.py— the four direct helper calls updated to the new signature (floor=None); all 37 behaviour assertions unchanged and green.docs/memory/architecture/execution.md,docs/memory/feature-flows/cleanup-service.md,docs/memory/learnings/2026-10-13-agent-timestamps-bounded-both-ends.md,docs/security-reports/cso-diff-2026-10-13-ent882-completed-at-floor.md— the helper's rule list, the claim flow clause, the learnings fragment, the diff audit.Test Plan
test_a_backdated_envelope_lands_as_started_at_in_the_column,test_the_failed_arm_floors_too,test_a_backdated_close_lands_as_started_at_in_the_column, and the 7 helper-rule tests).cd tests && pytest unit/test_882_completed_at_floor.py unit/test_3589_claim_completed_at.py -v— 52 passed (15 new + 37 existing).Fixes abilityai/trinity-enterprise#882 (private tracker — cross-repo keyword does not auto-close; closed manually at release).
Rides rc3 together with t#3588.
🤖 Generated with Claude Code