Repository navigation
fix: preserve same-session hook bursts - #110575
Conversation
8224b10 to
ba40f9f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8224b101f5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| runId, | ||
| jobId, | ||
| void runWithGatewayIndependentRootWorkContinuation(() => | ||
| enqueueHookAgentDispatch(sessionKey, async () => { |
There was a problem hiding this comment.
Queue by the canonical cron session key
When hook requests use different aliases for the same target session, such as configured/default main and an explicit agent:main:main (or configured mainKey aliases), this queue treats them as separate keys and lets both runs start in parallel. The cron runner canonicalizes input.sessionKey later via resolveCronAgentSessionKey before lifecycle claiming (src/cron/isolated-agent/run.ts:645), so those aliases still collide on the same persisted session and can hit the same CronSessionLifecycleClaimError burst loss this change is meant to prevent; the queue key needs to be the same canonical session key the cron run will claim.
Useful? React with 👍 / 👎.
72851b8 to
6087e9d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6087e9d558
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| runId, | ||
| jobId, | ||
| void runWithGatewayIndependentRootWorkContinuation(() => | ||
| enqueueHookAgentDispatch(sessionKey, async () => { |
There was a problem hiding this comment.
Include the target agent in hook queue keys
When hooks are enabled for multiple agents and callers use an unscoped key such as the default main, normalizeHookDispatchSessionKey leaves the key unscoped while the run is still targeted via job.agentId. Queueing only by sessionKey means a slow or stuck hook for one agent now blocks hooks for another agent with the same unscoped key, even though downstream session resolution scopes those runs by agent. Key the FIFO by the effective/canonical agent session identity so only truly shared sessions serialize.
Useful? React with 👍 / 👎.
6087e9d to
e308bb4
Compare
|
Codex review: needs real behavior proof before merge. Reviewed July 18, 2026, 5:55 AM ET / 09:55 UTC. Summary PR surface: Source +25, Tests +86. Total +111 across 2 files. Reproducibility: no. high-confidence live reproduction was performed in this review. The linked report provides a concrete current-style scenario—send three same-session agent hooks while cron concurrency exceeds one—and the source path supports that race model. Review metrics: none identified. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review detailsBest possible solution: Keep one FIFO queue per canonical effective agent-session identity, retain independent parallelism for distinct sessions, and add a redacted real gateway burst transcript showing all events are processed in order. Do we have a high-confidence way to reproduce the issue? No high-confidence live reproduction was performed in this review. The linked report provides a concrete current-style scenario—send three same-session agent hooks while cron concurrency exceeds one—and the source path supports that race model. Is this the best way to solve the issue? Unclear: a FIFO is the narrow maintainable shape if its key is the same canonical effective agent-session identity claimed by cron, but real gateway evidence and maintainer confirmation of that boundary are still needed. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against fcdf06ed2944. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +25, Tests +86. Total +111 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (1 earlier review cycle)
|
e308bb4 to
988a1db
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 988a1db193
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // settings. Otherwise reload can move one FIFO entry to another session. | ||
| job.agentId = agentId; | ||
| void runWithGatewayIndependentRootWorkContinuation(() => | ||
| enqueueHookAgentDispatch(queueKey, async () => { |
There was a problem hiding this comment.
Avoid serializing detached hook runs
When multiple hooks reuse a normal key such as hook:ingress or agent:main:main, this queues every later request for the full duration of the preceding agent turn. However, each hook job still has sessionTarget: "isolated" (src/gateway/server/hooks.ts:168), so runCronIsolatedAgentTurn replaces every non-cron base key with the unique cron:${job.id} before lifecycle admission (src/cron/isolated-agent/run.ts:642-653). These runs therefore do not claim the same runtime session, and the new FIFO needlessly converts webhook bursts into a potentially minutes-long serial backlog; queue only targets that actually share a lifecycle key, or use a non-detached job target if shared-session execution is intended.
Useful? React with 👍 / 👎.
988a1db to
249ca7e
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 249ca7e627
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return runId; | ||
| } | ||
| const agentId = value.agentId ?? resolveDefaultAgentId(dispatchCfg); | ||
| const queueKey = resolveCronAgentSessionKey({ |
There was a problem hiding this comment.
Preserve agent scope in global-session queue keys
When session.scope is "global" and hooks target different agents, resolveCronAgentSessionKey canonicalizes each agent's main alias to the same literal global, so the process-wide queue makes a slow hook for one agent block hooks for every other agent. Those runs remain agent-scoped because runCronIsolatedAgentTurn receives the resolved agentId and resolveCronSession selects an agent-specific store path. Fresh evidence beyond the earlier agent-key comment is the global-scope canonicalization in src/config/sessions/main-session.ts combined with the agent-specific store selection in src/cron/isolated-agent/session.ts; retain the agent dimension in the queue key even when the canonical session component is global.
Useful? React with 👍 / 👎.
| try { | ||
| // Agent hooks run after the HTTP response path has returned, so failure | ||
| // handling must record a system event instead of throwing to the caller. | ||
| const cfg = getRuntimeConfig(); |
There was a problem hiding this comment.
Keep reload-time routing aligned with the fixed queue key
When session.mainKey or session.scope changes while a same-key hook is waiting, its queue key remains canonicalized with the acceptance-time config, but this fresh config causes the runner to recanonicalize the original sessionKey under the new routing contract. A hook accepted after the reload uses the new queue and can therefore start alongside the older waiting hook even though both resolve to the same execution-time session identity, defeating the FIFO guarantee and reopening the race this change is intended to prevent.
Useful? React with 👍 / 👎.
|
Merged via squash.
|
* fix(gateway): serialize same-session agent hooks * fix(gateway): canonicalize queued hook sessions * fix(gateway): preserve hook runner routing contract * docs(gateway): explain hook reload identity
* fix(gateway): serialize same-session agent hooks * fix(gateway): canonicalize queued hook sessions * fix(gateway): preserve hook runner routing contract * docs(gateway): explain hook reload identity
Closes #110109
What Problem This Solves
Fixes an issue where multiple
/hooks/agentevents targeting the same underlying agent session could race the cron session lifecycle claim and lose later events.Why This Change Was Made
Agent hook dispatch now canonicalizes the target agent and session when the hook is accepted, then uses a per-session FIFO inside tracked detached gateway work. Alias forms such as
mainandagent:main:mainshare one queue. Different sessions remain parallel. Runtime settings are refreshed when queued work starts, while the accepted target identity remains stable across config reloads. Failed runs and config-load failures preserve detached error reporting and do not block later queue entries.The isolated-agent module load is shared so independent session queues can start concurrently.
AI-assisted maintainer fix.
User Impact
Webhook bursts for one session no longer drop loser events as non-retryable
CronSessionLifecycleClaimErrorfailures. Operators retain normal parallelism across unrelated sessions without lowering global cron concurrency.Evidence
corepack pnpm test src/gateway/server/hooks.agent-trust.test.ts— 15/15 passed on Blacksmith Testboxtbx_01kxv49hrwfwb5jr1xx0cqdj1t.corepack pnpm test src/gateway/server/hooks.agent-trust.test.ts src/gateway/server.hooks.test.ts— 40/40 unit and HTTP integration tests passed on fresh Testboxtbx_01kxv6v2pjbwmgd48atbwh8y7x.corepack pnpm check:changed -- src/gateway/server/hooks.ts src/gateway/server/hooks.agent-trust.test.ts— passed, including core/core-test typechecks, lint, format, boundaries, import cycles, and gateway guards.cron-model-created-one-shot-recurringpassed in 4m42s with an isolated random-port gateway: model-authored one-shot ran once and was deleted; recurring ran repeatedly, survived restart, and retained a future next run.$autoreview --mode branch --base origin/mainplus focused follow-up reviews — no accepted/actionable findings.249ca7e62727.