Skip to content

fix: P0 #5369 spill growth + P1 bug batch (#5421, #5008, #4191, #3522, #4779, #3661) - #5825

Merged
lidge-jun merged 37 commits into
devfrom
devin/1790312206-p0-p1-bugfix-lane
Sep 25, 2026
Merged

lidge-jun merged 37 commits into
devfrom
devin/1790312206-p0-p1-bugfix-lane

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR combines the P0 fix and the P1 bug fixes. Each child worker's result was reviewed before it was added, and every issue keeps its own focused commits.

P0 #5369: responses-state-spill/ grows without bound

  • Periodic orphan reclaim: sweepOrphanedResponseSpills() now runs on the responses-continuation liveness tick. It is bounded (PERIODIC_SPILL_SWEEP_OPTS = {scanMax: 512, cleanupMax: 64, deadlineMs: 25}), keeps the 15-minute grace period, and does nothing until the store has loaded.
    • Files it treats as still in use: live spill stubs, pendingSpillUnlinks, and queued or in-flight publication names (spillQueueReferencedSpillFileNames(): superseded spill, temp, destination).
    • Before this change, orphans were only reclaimed in the lazy ensureLoaded(), so a long-running hub never reclaimed them.
  • Snapshot budget: writeBoundedSnapshot now picks bounded stubs and tombstones before resident entries. Previously the newest-first resident cohort could use the whole 24 MiB budget, drop spill stubs, and leave their files orphaned after a restart.
  • Diagnostics (read-only): inspectResponseSpillDir() / inspectResponseSpillStorage() share one orphan predicate and one directory scan with the reclaim, so they always agree with it. Results appear in ocx doctor ("Response-state spill files") and in the responseSpill field of /api/system/memory. There is a new troubleshooting doc section.
  • One ownedSpillFileNames() reference set is shared by the load-time GC, the periodic sweep and the inspector.

P1 #5421: DeepSeek reasoning_text HTTP 400. On the Responses wire, sanitizeReasoningInputContent({ requirePlaintextReasoning }) now fills in reasoning_text from summary_text, or uses " " if there is none. This applies only to providers where requiresPlaintextReasoningReplay is true. deepseek-v4-pro is added to preserveReasoningContentModels.

P1 #5008: Antigravity 400 when a request opens with a function call. When compaction leaves a model turn containing functionCall at index 0, messagesToGeminiFormat now puts {role:"user", parts:[{text:"(continue)"}]} in front of it.

P1 #4191: diagnosing a dead Codex WebSocket. Adds firstResponseMs (time from send to the first non-control response.* or error frame) to the WS stage record and the failure detail (first-response=). Usage-log records written before this field existed still load, with the field set to null. The worker's version would have dropped them, so a fix and a test were added for that.

P1 #3522: Windows spill failures pile up while readiness reports healthy. Once the windows-secret-acl timeout memo had used its one recovery attempt, it refused every later harden for the stable spill directory. That broke durable publication for the rest of the process's life. The memo now re-arms after TIMEOUT_MEMO_REARM_MS (5 min), and only for callers that pass retryTimedOutOnce. Callers without the flag are still refused immediately.

P1 #4779: Task Scheduler staging unreadable under an alternate-credential UAC prompt. New hardenElevatedStagePath/Dir give the owner full control and give read-only access to SYSTEM and BUILTIN\Administrators. They are used only for the elevated scheduler staging payloads, which are integrity-checked with SHA-256. Secret call sites keep owner-only ACLs, and the two shapes have separate memo caches. The owner-only "already compliant" shortcut is also skipped for the staging shape.

P1 #3661: unreadable_encrypted_agent_task. Adds an opt-in agentTaskRecovery.retries setting (0–2, default 0) that retries recovery only on transient 5xx or transport errors. Retries share the caller's deadline, admission and cache flight. Default behaviour is unchanged.

No code change (findings only):

Verification

  • bun run typecheck, bun run privacy:scan, bun run structure:check: all pass.
  • (cd docs-site && bun run build): 505 pages built.
  • bun test tests/responses/: 3146 pass, 0 fail.
  • bun test tests/windows/ tests/server/agent-task-recovery.test.ts tests/server/config.test.ts: 722 pass, 0 fail.
  • DeepSeek replay, provider parity and reasoning-effort tests: 126 pass.
  • Doctor, memory-watchdog and spill tests: 252 pass.
  • WS stage and usage-log tests: 154 pass.
  • bun test tests/adapters/google/: 655 pass, 1 fail (google-models-listing bearer token). That file passes on its own (14/14), so this looks like shared state between parallel test files.
  • bun run test:changed: 25649 pass, 26 fail. All 26 failures are in 9 files (service claim/ownership/sqlite-home/WSL/service, native codex/grok toggle, reserve-catalog-lifecycle, replay-refusal-parity). Each of those files passes when run on its own, which points to shared-home contention between parallel test files; none of them touch the code changed here.
  • Windows ACL behaviour ([Bug][Windows] Continuation spill failures accumulate behind healthy readiness after #3011 (observed on 2.39.0) #3522, [Bug][Windows]: elevated Task Scheduler staging is unreadable under alternate-credential UAC #4779) was tested with an injected icacls runner only. It has not been run on real Windows.

Checklist

Link to Devin session: https://app.devin.ai/sessions/c3784bc025a148d3bf396fe4623542cb
Open in Devin Desktop: https://app.devin.ai/desktop/session/c3784bc025a148d3bf396fe4623542cb?variant=devin

Maintainer regression verification

  • Security review of src/lib/windows-secret-acl.ts / windows-ops.ts ([Bug][Windows]: elevated Task Scheduler staging is unreadable under alternate-credential UAC #4779, [Bug][Windows] Continuation spill failures accumulate behind healthy readiness after #3011 (observed on 2.39.0) #3522): the elevated-stage shape is a separate export used only by the non-secret, SHA-256-verified scheduler staging payloads. It grants read and never write to SYSTEM and Administrators, and the secret call sites still get the owner-only ACL. The timeout-memo re-arm applies only to retryTimedOutOnce callers. Applied maintainer-sponsored.
  • The same suites (tests/responses/ tests/windows/ tests/providers/ tests/adapters/google/ tests/usage/ + touched server/doctor/watchdog tests) were run on the PR head and on the dev tip: PR 10679 pass / 38 fail, dev 10629 pass / 38 fail, with an identical failure set (kiro/xAI/account-pool shared-state, and protocol-direct-encoders-chat stall watchdog). No regressions; the PR adds 50 passing tests.
  • The CI test 1/4 / macos 1/2 failure (stall watchdog fails the turn like the bridge) reproduces on the dev tip too. This PR did not cause it.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

lidge-jun and others added 29 commits September 24, 2026 21:56
…ng replay (#5421)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… and preserve reasoning on v4-pro (#5421)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The only orphan GC pass ran once inside ensureLoaded(), so orphans created
while the process kept running — crash leftovers, failed best-effort
unlinks, stubs the snapshot budget cut — survived until the next restart.

sweepOrphanedResponseSpills now rides the responses-continuation liveness
tick alongside the abandoned-temp sweep. Its referenced set covers live
spill stubs, pendingSpillUnlinks, and every queued/in-flight publication
name from the spill queue, and it runs under tighter periodic bounds
(scan 512 / cleanup 64 / 25 ms deadline) since the tick is synchronous
on the serving event loop. It is a no-op before the lazy load runs.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…-home

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…all turn (#5008)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
#5008)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Regression coverage for a read-only inspector over responses-state-spill:
totals vs store-owned vs orphan candidates past the orphan grace, report/
reclaim agreement, scan-cap truncation, and the snapshot-ownership path a
separate doctor process relies on.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Operators cannot tell owned spill bytes from orphaned ones on disk.
inspectResponseSpillDir walks responses-state-spill with the same name/
stat orphan predicate as recoverOrphanedResponseSpills — extracted into
shared helpers so the report and the unlink cannot disagree — and counts
totals, store-owned files, and orphan candidates past the grace window
without ever unlinking. inspectResponseSpillStorage supplies the
referenced set as the union of live spill stubs, pending unlinks, and
names the persisted snapshot still references, so a separate doctor
process sees the same ownership a restart would.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
ocx doctor gains a "Response-state spill files" section via
formatResponseSpillLines: totals on disk, bytes still owned by the store
or persisted snapshot, and orphan candidates past the grace window —
report only, never unlink. /api/system/memory gains a scalar-only
responseSpill sibling of the pinned responseState block with the same
counts.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Explain what responses-state-spill/ holds, its three bounds (1 GiB
payloads, 1000 entries, 24h TTL), why a restart re-owns every referenced
file, and that the orphan reclaim handles unreferenced leftovers — so
operators should not delete spill files by hand. Points at the new
"Response-state spill files" section in ocx doctor and the
responseSpill block on /api/system/memory for the owned-vs-orphan split.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…aim and doctor (#5369)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…stage record (#4191)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… the WS stage record (#4191)

The stage record could already tell a silent socket from one that carried
only quota control frames, but send->first-frame is measured on ANY inbound
frame: a peer that answers quota metadata then stalls on the turn itself
reads identically to one that answered and started immediately. The
reporter's remaining unmeasured axis is the wait for the first real
Responses event (response.created and friends).

firstResponseMs is stamped on the first non-control response.*/error frame
the relay observes, feeds the failure message suffix and the durable stage
record, and survives the usage-log drop-guard like its sibling durations.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…drate (#4191)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ured (#4191)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Cover the consumed stable-directory timeout memo: after the re-arm
window the spill queue's caller-owned retry must get one bounded
recovery attempt, and a still-stalled runner must get at most one
bounded probe per window instead of instant refusals forever.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…et window (#3522)

Once the spill directory's "required:<dir>" timeout memo was consumed,
retryTimedOutOnce callers were refused forever: the memo only clears on
a successful harden, which the refusal makes unreachable. On Windows a
single stalled icacls then bricked every continuation spill write for
the life of the process -- successes froze, write failures accumulated,
and readiness stayed healthy (2.39.0 incident signature).

A consumed memo now re-arms after TIMEOUT_MEMO_REARM_MS (5min) of
quiet -- strictly above the per-harden deadline cap so a stalled run
produces at most one bounded probe per window, and only for callers
carrying retryTimedOutOnce. Flagless callers keep the instant refusal;
a successful harden still deletes the memo outright.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ntial UAC (#4779)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…uler payloads (#4779)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…or the elevated-stage shape (#4779)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… recovery (#3661)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ransient upstream failures (#3661)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…apshot budget

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… the bounded snapshot

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… before residents

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
lidge-jun and others added 3 commits September 24, 2026 22:51
inspectResponseSpillStorage reads the snapshot and walks the spill directory
synchronously; reuse one result per 30 s window instead of rescanning per request.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…E shapes on the async path (#4779)

Mirrors the synchronous hardenEntry guard so an async caller of the elevated
staging shape cannot accept an owner-only ACL as already compliant.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

리뷰 반영했습니다 (최신 push):

  • 주기 청소 512개 창: sweepOrphanedResponseSpillsPeriodically가 틱 사이에 재개 위치를 기억합니다 (skip 옵션, 전체를 한 바퀴 돌면 0으로 리셋, 지운 개수만큼 위치 보정). 소유 파일 576개 + 고아 29개 중 고아 대부분이 512번째 뒤에 있는 상황에서 3틱 안에 전부 회수되는지 보는 회귀 테스트를 추가했습니다.
  • /api/system/memory 스캔 비용: spill 리포트를 30초 TTL로 캐시합니다. ocx doctor는 계속 매번 새로 읽습니다.
  • hardenEntryAsync: 동기 경로와 같은 extraReadAces.length === 0 조건을 넣었습니다.
  • 추가로 macOS 샤드의 file-size ratchet 실패도 고쳤습니다. state.ts가 캡(1371줄)을 넘어서 스냅샷 선택 로직을 state/snapshot-select.ts로 뺐고, 새 dev도 머지했습니다 (openai-chat.ts 캡 초과는 예전 merge-base 쪽 문제였고 새 dev에서 이미 고쳐져 있었습니다).

maintainer-sponsored 라벨과 실제 Windows에서의 #4779 확인은 메인테이너 판단으로 남겨 둡니다.

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Maintainer triage: priority: P0 — fixes P0 #5369 unbounded responses-state-spill growth plus a batch of P1 core-path bugs.

Criteria (P0): Critical: security/credential exposure, auth bypass, data loss, or unbounded resource growth on a running hub; no workaround.

Related issues:

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

Review readiness checklist

  • ✅ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ✅ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

✅ 4/4 boxes ticked.

This pull request is already Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently.
Maintainers: @lidge-jun @Ingwannu

@github-actions
github-actions Bot marked this pull request as draft September 25, 2026 06:11
lidge-jun and others added 4 commits September 25, 2026 16:10
…en across ticks (#5369)

The offset cursor re-skipped from a fresh opendir each tick, and that skip
spent the 25 ms deadline, so a slow enumeration left scanned=0 and pinned
the cursor at the same prefix forever. Hold the real iterator instead,
never read a name the tick will not process, and drop it at EOF, on an
iteration error, or when the spill directory changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Zero orphans in the first RESPONSE_SPILL_SCAN_MAX entries says nothing
about the unscanned tail; warn instead of printing the ok line and
swallowing the truncation notice.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…covery deadline (#3661)

The retry helper clamped Retry-After to the 2 s backoff cap, so a
Retry-After: 30 resent after 2 s. Pass retryAfterIsLowerBound and end
with the current failure when the required wait would outlive the
shared recovery deadline.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@lidge-jun
lidge-jun marked this pull request as ready for review September 25, 2026 07:51
@lidge-jun lidge-jun added the maintainer-sponsored Maintainer sponsors this change to an auth, workflow, release, or dependency surface label Sep 25, 2026
@github-actions github-actions Bot removed the intake: hygiene-blocked Deterministic PR hygiene checks failed label Sep 25, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-25T07:57:24.579464Z 255b9e0 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions
github-actions Bot marked this pull request as draft September 25, 2026 07:51
@lidge-jun
lidge-jun marked this pull request as ready for review September 25, 2026 07:52
@lidge-jun
lidge-jun merged commit 22b22ae into dev Sep 25, 2026
45 of 53 checks passed
@lidge-jun
lidge-jun deleted the devin/1790312206-p0-p1-bugfix-lane branch September 25, 2026 07:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 255b9e0a2d

ℹ️ 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".

Comment on lines +487 to 490
firstResponseAt ??= Date.now();
try {
if (nativeControl) steeringEnded = nativeControl.observe(normalized.payload);
else correlation?.accept(normalized.payload);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Record first-response time only after correlation succeeds

On a reused Codex WebSocket session, a foreign or mismatched response.* frame sets firstResponseAt before correlation.accept() or nativeControl.observe() rejects it. The resulting non-replayable 502 and persisted usage record therefore report a non-null first-response duration even though no event for this turn was accepted or relayed, undermining the diagnostic distinction this field was added to provide. Set the timestamp only after correlation validation returns successfully.

Useful? React with 👍 / 👎.

@lidge-jun lidge-jun mentioned this pull request Sep 25, 2026
10 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working maintainer-sponsored Maintainer sponsors this change to an auth, workflow, release, or dependency surface priority: P0 Critical: security/credential exposure, auth bypass, data loss, or unbounded resource growth on a ru review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant