Repository navigation
Description
Found while validating #2120.
Context — the unbounded wait is deliberate, and correct
#2120's review fixed a real double-billing chain: awaitPersistedReply used to budget a fixed ~10.5s from stream end, so any turn persisting later (notably the cold --resume retry, which re-runs the WHOLE turn) was rendered "not delivered" with a Retry that ran and billed it a second time.
The fix makes the wait bounded by the server's answer instead of a stopwatch, which is the right shape:
// components/portal/PortalConversation.vue
for (;;) {
...
if (data.inFlightExecutionId) { idlePolls = 0 }
else if (++idlePolls >= REPLY_IDLE_GIVE_UP) return null
await new Promise((r) => setTimeout(r, REPLY_POLL_MS)) // 700ms
}The residual
The loop has no absolute ceiling. It exits only when the server stops reporting an in-flight execution. That marker is cleared in a finally on every exit path of start_portal_turn._run, so the normal case is fine — but except Exception does not catch CancelledError, and a hard backend kill skips the finally entirely. The marker then survives until its TTL:
def mark_turn_inflight(session_id, execution_id, ttl_seconds: int = 3600) -> None:One hour. At REPLY_POLL_MS = 700 that is ~5,100 GET /history requests from a single tab, each hitting the DB, for a turn that is already dead. Multiple tabs multiply it. Nothing in the UI tells the user the turn is not coming.
Suggested fix
A generous absolute ceiling that cannot be hit by a legitimate turn — the agent's own execution timeout plus the cold-retry allowance (so roughly 2 × execution_timeout + buffer) — after which the UI reports that it lost track of the turn and points at history, without offering a Retry (the original billing hazard).
Worth pairing with a wider poll interval once elapsed time is large, so a long legitimate turn costs far fewer requests.
Acceptance criteria
- The poll cannot run unbounded when the in-flight marker is stale
- A legitimately long turn (including one cold retry) still resolves normally — no regression of the feat(workspace): absorb the Session surface, with continuity parity (ent#358) #2120 fix
- Giving up does not offer Retry for a turn that may have run
- Regression test naming this issue
Related: #2120, abilityai/trinity-enterprise#358, abilityai/trinity-enterprise#286
Activity
fix(tests): remove the ambiguous alternation CodeQL flagged as ReDoS (#…
fix(workspace): address the review findings on this PR (#2133)
fix(workspace): bound the reply poll to a turn's real life, and stop …
Merge origin/dev into feature/ent361-mention-to-group
fix(portal): the Workspace turn bound is the agent's own execution ti…
fix(workspace): a failed turn says so, and Retry follows the billing …
fix(workspace): a failed turn says so, and Retry follows the billing …
fix(workspace): a failed turn says so, and Retry follows the billing …
fix(workspace): a failed turn says so, and Retry follows the billing …