Skip to content

fix(cloud-agent): serialize concurrent codex prompts to fix usage accounting#1721

Merged
tatoalo merged 1 commit into
mainfrom
fix/codex-prompt-serialization
Apr 20, 2026
Merged

fix(cloud-agent): serialize concurrent codex prompts to fix usage accounting#1721
tatoalo merged 1 commit into
mainfrom
fix/codex-prompt-serialization

Conversation

@tatoalo
Copy link
Copy Markdown
Contributor

@tatoalo tatoalo commented Apr 17, 2026

Problem

codex-acp and codex-rs serialize submissions at the conversation level, so concurrent prompts are safe from codex's perspective. But our adapter accumulates per-turn usage into sessionState.accumulatedUsage via the codex-client sessionUpdate handler, and each prompt() starts with resetUsage(). If two prompts run concurrently on the JS side — e.g. two concurrent /command POSTs (a Slack follow-up racing a web-UI follow-up, or a retry after an HTTP timeout) — the second prompt's resetUsage wipes the first's in-flight counters and both TURN_COMPLETE notifications report garbled totals.

Changes

Chain CodexAcpAgent.prompt calls through a FIFO promise mutex so the usage accumulator has a single owner per turn. Errors on one prompt do not block subsequent prompts (.catch(() => {}) on the previous tail).

How did you test this?

  • New unit test: two concurrent prompt() calls serialize — the second does not invoke codexConnection.prompt until the first resolves.
  • New unit test: a failing prompt does not block the next one.
  • Full @posthog/agent suite green (263 tests).

Copy link
Copy Markdown
Contributor Author

tatoalo commented Apr 17, 2026

@tatoalo tatoalo force-pushed the fix/codex-loadsession-task-run branch from 463eb7f to bfbea4d Compare April 17, 2026 16:59
@tatoalo tatoalo force-pushed the fix/codex-prompt-serialization branch 2 times, most recently from 9e6b0fb to 0b35e19 Compare April 17, 2026 17:02
@tatoalo tatoalo marked this pull request as ready for review April 17, 2026 17:07
@tatoalo tatoalo requested a review from a team April 17, 2026 17:07
@tatoalo tatoalo force-pushed the fix/codex-loadsession-task-run branch from bfbea4d to f00c114 Compare April 20, 2026 09:25
@tatoalo tatoalo force-pushed the fix/codex-prompt-serialization branch from 0b35e19 to 7321bd4 Compare April 20, 2026 09:25
@tatoalo tatoalo force-pushed the fix/codex-loadsession-task-run branch 2 times, most recently from 65f3732 to 4fee8b5 Compare April 20, 2026 09:36
@tatoalo tatoalo force-pushed the fix/codex-prompt-serialization branch from 7321bd4 to 3af3e64 Compare April 20, 2026 09:36
@tatoalo tatoalo changed the base branch from fix/codex-loadsession-task-run to graphite-base/1721 April 20, 2026 09:45
@tatoalo tatoalo force-pushed the graphite-base/1721 branch from 4fee8b5 to 99ebc97 Compare April 20, 2026 09:45
@tatoalo tatoalo force-pushed the fix/codex-prompt-serialization branch from 3af3e64 to 229deb0 Compare April 20, 2026 09:45
@graphite-app graphite-app Bot changed the base branch from graphite-base/1721 to main April 20, 2026 09:45
@tatoalo tatoalo force-pushed the fix/codex-prompt-serialization branch from 229deb0 to 1ba067c Compare April 20, 2026 09:45
@tatoalo tatoalo merged commit d398e4a into main Apr 20, 2026
15 of 16 checks passed
Copy link
Copy Markdown
Contributor Author

tatoalo commented Apr 20, 2026

Merge activity

@tatoalo tatoalo deleted the fix/codex-prompt-serialization branch April 20, 2026 09:55
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.

2 participants