Skip to content

Fix command timeline durations after approval - #5108

Merged
ymichael merged 2 commits into
mainfrom
bb/exclude-approval-wait-from-command-durations-thr_gf3mtytbw6
Oct 7, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/exclude-approval-wait-from-command-durations-thr_gf3mtytbw6

Conversation

@ymichael

@ymichael ymichael commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Claude Code emits a command start before asking for permission. The timeline kept that timestamp after the user approved, so an instant command could show minutes spent waiting for Allow once as execution time.

What changed

Use successful command approval resolution as the execution start, clear the waiting state, and carry the updated timestamp through running and completed rows. Preserve the original row and sequence when another tool appears during approval. Completed executions that reuse a call ID remain separate.

Add a regression for Allow once and session approval, including an interleaved command and the displayed duration label. Update the server API test to expect the waiting state to clear after successful approval. No wire or public API changes.

How you verified

  • The regression failed before the fix with the pre-approval start time and waiting state.
  • pnpm exec turbo run test typecheck lint --filter=@bb/thread-view: 450 tests and typecheck passed. The package has no lint task.
  • pnpm exec turbo run typecheck lint --filter=@bb/thread-view --filter=@bb/app: passed; app lint reports existing warnings and no errors.
  • Direct Oxlint passes for all changed files. A full thread-view scan reports four pre-existing comment-rule violations in user-message-parsing.ts, confirmed against HEAD.
  • Reviewed before/after screenshots of real timeline projection and components in a temporary Ladle story at 1280×800 and 390×844. The inflated 2m 24s label disappears for a 100ms execution. Screenshots and the fixture are saved in thread storage. iOS Safari was not tested.
  • pnpm exec turbo run test --filter=@bb/server -- test/public/public-thread-interactions.test.ts: all 25 tests passed. Server typecheck passed through Turbo, and direct Oxlint passed for the changed test file.
  • git diff --check: passed.

AGENT GENERATED

ymichael and others added 2 commits October 7, 2026 01:03
## Human comments

## What was wrong

Claude Code emits a command start before requesting permission. The timeline
kept that timestamp after approval, so a command that ran instantly could show
a duration of several minutes spent waiting for the user.

## What changed

Treat a successful command approval resolution as the execution start. Clear
the waiting state and carry the new start time through running and completed
rows while preserving the original sequence. Update an ongoing command's
existing history row when another tool appeared during approval. Keep reused
call IDs as separate executions after completion.

Add a timeline regression for Allow once and session approval, including an
interleaved command and the displayed duration label.

## How you verified

- Confirmed the regression failed before the fix with the original start time
  and waiting state.
- `pnpm exec turbo run test typecheck lint --filter=@bb/thread-view` passed:
  450 tests and typecheck. This package has no lint task.
- `pnpm exec turbo run typecheck lint --filter=@bb/thread-view --filter=@bb/app`
  passed; app lint reported existing warnings and no errors.
- Direct Oxlint passed for all changed files. The full thread-view scan reports
  four pre-existing no-comments errors in user-message-parsing.ts, confirmed
  against HEAD.
- Rendered the real projection and timeline components in a temporary apps/app
  Ladle story served through Turbo. Reviewed before/after screenshots at
  1280x800 and 390x844, saved with the fixture in thread storage. The inflated
  2m 24s label disappears for a 100ms execution. iOS Safari was not tested.
- `git diff --check` passed.

> AGENT GENERATED
## What was wrong

The server route test expected a successfully approved command to retain its
waiting-for-approval state, conflicting with the corrected timeline lifecycle.

## What changed

Expect the approved pending command's approvalStatus to be null.

## How you verified

- All 25 public thread interaction route tests passed through Turbo.
- Server typecheck passed through Turbo; this package has no lint task.
- Direct Oxlint passed for the changed test file.
- git diff --check passed.

> AGENT GENERATED
@ymichael
ymichael merged commit c40cfd9 into main Oct 7, 2026
47 checks passed
@ymichael
ymichael deleted the bb/exclude-approval-wait-from-command-durations-thr_gf3mtytbw6 branch October 7, 2026 18:04
ymichael pushed a commit that referenced this pull request Oct 8, 2026
## Human comments

## What was wrong

When the main agent sends a follow-up to a Codex sub-agent that has
finished, the Codex translator reopened the sub-agent's original
delegation item: the same id, in the turn that first spawned it. The
timeline projection only merges a start event into an existing row while
that call is still running, so each reopen added another row with the
same id (`onExecBegin` in `tool-activity-projection.ts`). Children
attach to a delegation by call id, so every copy rendered the
sub-agent's entire history. When a sub-agent also followed up its own
sub-agents, the copies multiplied at every level. That is the
exponential growth in #5210 that exhausted the server heap. Even without
nesting, threads showed one delegation many times; one local thread
rendered a sub-agent 14 times, with 2,609 timeline rows instead of 982.

## What changed

- **`plugins/provider-codex/src/translator.ts`:** a follow-up to a
finished sub-agent starts a new delegation. Its id is the follow-up
interaction's own id, it is placed in the parent turn that sent the
follow-up, and it uses the same path as a newly spawned sub-agent. Each
round now appears in the turn where it happened and contains only that
round's work. Follow-ups queued while the sub-agent is still running
stay in the current round. Nested follow-ups attach to the parent's
current round.
- **`packages/thread-view/src/tool-activity-projection.ts`:** a start
event for a finished delegation reopens its existing row instead of
adding a copy. This fixes threads already stored with reused ids: they
show one row per sub-agent, holding every round. Commands keep #5108's
behaviour, where a reused call id gets its own row.
- **`packages/thread-view/src/normalize-event-projection.ts`** (from the
original version of this PR): each delegation keeps one child per
message id. This is a backstop against exponential growth if duplicate
ids arrive from another source.
- **Dropped from the original version:** the incremental byte budget in
`timeline-pagination.ts`. The oversized tree is fully built before
pagination serializes it, so that change didn't address the crash.
- No wire, schema, CLI, or plugin API changes.

## How you verified

- New `delegation-item-projection` test: a delegation reopened by a
follow-up, with a nested sub-agent that is also reopened, renders one
row per delegation with all child messages. It runs in two variants, the
last round completing or still running. It fails on `main` and passes
with the projection change alone.
- Codex translator tests: a follow-up from a later parent turn opens a
new delegation in that turn, and the sub-agent's next turn links to it.
A new nested test checks that a sub-agent's follow-up to its own
sub-agent attaches to the parent's current round. Six tests fail on the
old translator.
- Replayed a stored Codex thread's 6,124 events through the projection:
the reopened delegations went from 14 and 6 copies to 1 each; timeline
rows fell from 2,609 to 982 and JSON from 14.6 MB to 3.9 MB.
- Ran real Codex end to end in a worktree dev instance: spawning a
sub-agent in turn 1 and following it up in turn 3 produced separate
`/root/counter` rows in turns 1 and 3, containing only "ONE" and only
"TWO".
- `pnpm exec turbo run test typecheck lint --filter='...[origin/main]'`:
38 tasks passed.

Fixes #5210

> AGENT GENERATED

---------

Co-authored-by: qa <qa@x>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant