Skip to content

improve(gateway): compose live session stress probes - #122519

Merged
steipete merged 5 commits into
mainfrom
stress/cloud-session-switching
Aug 12, 2026
Merged

steipete merged 5 commits into
mainfrom
stress/cloud-session-switching

Conversation

@steipete

@steipete steipete commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

OpenAI Responses may return a compaction checkpoint on a response.incomplete turn with no visible assistant text or usage. Session sanitization discarded that otherwise-empty assistant message, and terminal resolution only continued when local compaction had incremented its counter, so the opaque provider replay owner could be lost or the run could stop silently instead of replaying the checkpoint.

The authenticated Codex stress harness also treated multi-session runs as subagent-only and stopped after the first multi-session phase, preventing session switching, nested-agent communication, baseline turns, approval persistence, and restart/resume from composing in one campaign.

Why This Change Was Made

  • Preserve otherwise-empty assistant messages when they own a valid providerReplay checkpoint.
  • Continue terminal resolution after either local compaction or a Responses replay checkpoint, while retaining provider/API/model/base-URL identity validation and stale-replay rejection.
  • Exclude multi-session campaigns from the subagent-only fast path and remove the early flow break so the stress phases compose.
  • Make the reduced direct-OpenAI profile use the demonstrated deterministic threshold (1000, three dense turns). Local proactive compaction is disabled only in this live probe so it cannot consume the history the probe is measuring.
  • Invalidate Vitest's inlined state-schema transform cache when canonical SQL changes, eliminating stale generated-build state during replay E2E runs.
  • Collapse duplicated sanitization branches while retaining the replay-owner invariant.

Production defaults are unchanged except for the replay correctness fix: there is no global change to local compaction policy.

User Impact

Direct OpenAI Responses sessions can now persist and resume compaction-only incomplete turns instead of losing the checkpoint or ending with no visible outcome. Maintainers also get one bounded cloud-session campaign that covers session switching, nested sessions, cross-agent communication, approval persistence, and restart/replay together.

Evidence

  • Root-cause API diagnostic: official [email protected] streaming returned one first-class compaction add/done item with non-empty opaque replay state for both store=true (1.295s) and store=false (0.941s), terminating as response.incomplete: run.
  • Pre-rebase live patch campaign: fresh-build replay E2E passed; composed Codex app-server stress passed with two sessions, two approvals, four turns, multi-session/subagent/baseline/restart phases; exact owned Testbox cleanup completed: run.
  • Post-rebase focused validation: 184 tests passed across seven targeted files. The fresh-build replay E2E passed in 22.19s test time (504.10s shard including 11 build invocations); all focused shards completed in 560.92s.
  • node --max-old-space-size=8192 --import tsx scripts/generate-plugin-sdk-api-baseline.ts --check — passed.
  • Targeted oxfmt --check, git diff --check, and the generated plugin SDK baseline — passed.
  • Codex autoreview against origin/main — clean, no accepted/actionable findings; patch is correct (0.98 confidence).
  • Codex app-server contract checked directly in sibling source: thread/start, thread/resume, turn/start, spawn_agent, and inter-agent message/follow-up handlers match the composed harness semantics.

Production/tooling LOC: +15/-21 (net -6) | Tests/test support: +169/-41 | Docs: +3/-3

AI-assisted; maintainer-requested, source-reviewed, live-provider tested, and exact-head CI required before landing.

@clawsweeper

clawsweeper Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS maintainer Maintainer-authored PR labels Aug 12, 2026
@steipete steipete self-assigned this Aug 12, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 12, 2026
@clawsweeper

clawsweeper Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 12, 2026, 9:04 AM ET / 13:04 UTC.

ClawSweeper review

What this changes

The PR preserves OpenAI Responses compaction checkpoints through session sanitization and continuation, and composes the live Codex session stress probes.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this maintainer-owned PR open for manual merge review. The prior global-compaction-policy concern is resolved, and the replay repair is owner-boundary aligned; direct Codex app-server source inspection remains unavailable in this review environment.

Priority: P2
Reviewed head: 6d05d79b37f0f48c3137530105a027c981cfb755
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has focused owner and gateway-boundary coverage with a net-negative production delta; only the local Codex source-contract review remains unavailable.
Proof confidence 🌊 off-meta tidepool Not applicable: This is maintainer-owned work, so the external-contributor proof gate does not apply; the PR body nevertheless records live provider and composed harness runs.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is maintainer-owned work, so the external-contributor proof gate does not apply; the PR body nevertheless records live provider and composed harness runs.
Evidence reviewed 7 items Current failure boundary: Current main drops an assistant message once its content becomes empty, and terminal continuation only recognizes locally counted compaction; this leaves a provider-owned empty checkpoint without its owner or continuation path.
PR repair at the state owner: The PR head retains empty assistant messages only when they carry provider replay state, and recognizes the specific OpenAI Responses checkpoint before issuing the existing bounded visible-answer continuation.
Replay identity remains validated: The existing replay owner validates provider, API, model, base URL, session, and auth-profile identity before constructing a compaction input; the PR does not relax that contract.
Findings None None.
Security None None.

How this fits together

The embedded agent runner persists provider replay checkpoints in session history and uses them to continue incomplete OpenAI Responses turns. The gateway’s live Codex harness drives multi-session and restart probes against that runtime.

flowchart LR
  Provider[OpenAI Responses stream] --> Checkpoint[Compaction checkpoint]
  Checkpoint --> Session[Sanitized session history]
  Session --> Runner[Embedded agent runner]
  Runner --> Replay[Replay continuation]
  Harness[Live Codex stress harness] --> Runner
  Replay --> Outcome[Visible completed response]
Loading

Decision needed

Question Recommendation
Should this PR wait for direct inspection of the pinned Codex app-server source before its composed live-harness evidence is accepted for merge? Require direct contract proof: Inspect the matching Codex app-server source and let exact-head CI finish before merging.

Why: Repository policy requires the reviewing agent to inspect sibling Codex source for Codex-backed runtime claims; that checkout is absent here, so a maintainer must choose whether to supply that proof or accept the existing live-run evidence.

Before merge

  • Resolve merge risk (P1) - This changes persisted session replay ownership; although request-identity validation remains in place, the Codex app-server contract used by the composed live harness could not be inspected because the required sibling source checkout is unavailable.
  • Complete next step (P2) - A maintainer must satisfy the unavailable direct Codex contract check and await exact-head CI; no mechanical repair is identified.
Agent review details

Security

None.

PR surface

Source -13, Tests +126, Docs 0, Other +9. Total +122 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 3 8 21 -13
Tests 10 167 41 +126
Docs 1 3 3 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 9 0 +9
Total 15 187 65 +122

Review metrics

Metric Value Why it matters
Production versus test LOC production/tooling +15/-21 (net -6); tests/test support +169/-41; docs +3/-3 The bug repair is net-negative in production while adding focused owner and gateway-boundary coverage.
Compaction configuration surface 1 test-only override added; 0 production defaults changed The resolved prior finding confines proactive-compaction disabling to the live probe rather than changing operator behavior.

Stored data model

Persistent data-model change detected: serialized state: scripts/lib/state-schema-inline-plugin.mts, serialized state: test/gateway-openai-compaction-replay.e2e.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Verify replay ownership before merge (recommended)
    Confirm the pinned Codex app-server contract and exact-head CI so the persisted checkpoint and composed session probes remain safe across retries and restarts.
  2. Accept the existing live evidence
    Maintainers may accept the documented live campaign if they judge its source-contract coverage sufficient.

Technical review

Best possible solution:

Retain the owner-boundary replay repair and land only after direct inspection of the pinned Codex app-server contract and green exact-head CI confirm the composed harness proof.

Do we have a high-confidence way to reproduce the issue?

Yes: current main drops an empty checkpoint-owning assistant message and does not continue it without local compaction; the PR’s ephemeral gateway E2E encodes that deterministic provider sequence.

Is this the best way to solve the issue?

Yes for the replay defect: preserving the checkpoint at the session-history owner and using the existing bounded continuation is narrower than adding a fallback path; Codex harness proof still needs its direct contract check.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against fb9a62e99568.

Labels

Label changes:

  • add merge-risk: 🚨 session-state: The PR changes which empty assistant turns persist as replay owners and when an interrupted session is continued.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is maintainer-owned work, so the external-contributor proof gate does not apply; the PR body nevertheless records live provider and composed harness runs.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review merge-risk labels are merge-risk: 🚨 session-state.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded session-replay correctness repair with no evidence of an emergency-wide outage.
  • merge-risk: 🚨 session-state: The PR changes which empty assistant turns persist as replay owners and when an interrupted session is continued.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is maintainer-owned work, so the external-contributor proof gate does not apply; the PR body nevertheless records live provider and composed harness runs.

Evidence

What I checked:

  • Current failure boundary: Current main drops an assistant message once its content becomes empty, and terminal continuation only recognizes locally counted compaction; this leaves a provider-owned empty checkpoint without its owner or continuation path. (src/agents/embedded-agent-helpers/images.ts:105, fb9a62e99568)
  • PR repair at the state owner: The PR head retains empty assistant messages only when they carry provider replay state, and recognizes the specific OpenAI Responses checkpoint before issuing the existing bounded visible-answer continuation. (src/agents/embedded-agent-helpers/images.ts:114, 6d05d79b37f0)
  • Replay identity remains validated: The existing replay owner validates provider, API, model, base URL, session, and auth-profile identity before constructing a compaction input; the PR does not relax that contract. (packages/ai/src/transports/openai-responses-compaction-replay.ts:100, fb9a62e99568)
  • Boundary regression coverage: The PR’s gateway E2E starts an ephemeral gateway and model server, verifies the first checkpoint-only turn is continued, reads the durable session checkpoint, and verifies its replay on the next turn. (test/gateway-openai-compaction-replay.e2e.test.ts:65, 6d05d79b37f0)
  • Prior review finding resolved: The reduced long-context profile now disables embedded compaction only in the live-test configuration, rather than changing production compaction behavior. (test/helpers/openai-long-context-live.ts:200, 6d05d79b37f0)
  • Codex contract gap: The PR’s composed harness claim depends on Codex app-server behavior, but the required sibling source checkout was absent, so this review cannot independently certify that contract.

Likely related people:

  • steipete: History sampling shows Peter Steinberger as the dominant contributor across the central replay and harness files, and the PR timeline assigns this work to steipete. (role: historical area contributor and assigned PR owner; confidence: medium; files: src/agents/embedded-agent-helpers/images.ts, src/agents/embedded-agent-runner/run/terminal-resolution.ts, src/gateway/gateway-codex-harness.live-helpers.ts)
  • Vincent Koc: Current-main blame attributes the central baseline lines to Vincent Koc in the available grafted history. (role: recent current-main contributor; confidence: medium; commits: 716f996be8db; files: src/agents/embedded-agent-helpers/images.ts, src/agents/embedded-agent-runner/run/terminal-resolution.ts, src/gateway/gateway-codex-harness.live-helpers.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Inspect the matching Codex app-server source in a maintainer environment and wait for exact-head CI to complete.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-12T07:57:54.746Z sha a344bc9 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-12T11:01:28.891Z sha 0007b2af963a8c8e9d9fdf00d9694f894a013f4e :: found issues before merge. :: [P2] Keep multi-session probes out of the subagent-only fast path
  • reviewed 2026-08-12T12:01:00.300Z sha dda689e :: found issues before merge. :: [P2] Document the new local-compaction behavior

@steipete
steipete force-pushed the stress/cloud-session-switching branch from a344bc9 to 4d3a1b8 Compare August 12, 2026 09:17
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S and removed size: XS labels Aug 12, 2026
@steipete
steipete force-pushed the stress/cloud-session-switching branch from 4d3a1b8 to 0007b2a Compare August 12, 2026 10:23
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 12, 2026
@steipete
steipete force-pushed the stress/cloud-session-switching branch from 0007b2a to 0ae0868 Compare August 12, 2026 11:51
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: M and removed size: S labels Aug 12, 2026
@steipete
steipete force-pushed the stress/cloud-session-switching branch from 0ae0868 to dda689e Compare August 12, 2026 11:54
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. and removed P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Aug 12, 2026
@steipete
steipete force-pushed the stress/cloud-session-switching branch from dda689e to 3274252 Compare August 12, 2026 12:34
@steipete
steipete force-pushed the stress/cloud-session-switching branch from 3274252 to 6d05d79 Compare August 12, 2026 12:57

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The prior compaction-policy finding is resolved: the global local-compaction guard was removed, and only the direct live probe disables proactive compaction. The current head preserves/continues valid Responses replay checkpoints without changing production compaction defaults. The PR body now includes the bounded live OpenAI and composed Codex multi-session/subagent/restart evidence, exact timings, cleanup proof, focused post-rebase validation, and production LOC (-6 net).

@clawsweeper

clawsweeper Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 12, 2026
@steipete
steipete merged commit 2cb9a75 into main Aug 12, 2026
202 of 204 checks passed
@steipete
steipete deleted the stress/cloud-session-switching branch August 12, 2026 13:22

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants