Skip to content

fix(client): stop the local-credential observer when the runtime recycles to standalone - #8710

Merged
lidge-jun merged 1 commit into
devfrom
fix/dev-red6-recycle-credential-observer
Nov 13, 2026
Merged

lidge-jun merged 1 commit into
devfrom
fix/dev-red6-recycle-credential-observer

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

windows 5/14 failed in two dev batches in a row (43451726885, 43483630535) on tests/clients/route-intent-runtime-stop.test.ts "runtime recycle cancels its watch and tick before replacement handoff". The fixture's own case passed in under a second; then an unnamed hook "timed out after 5000ms" and the child reported 14,902 ms and 14,904 ms. The attribution sweep reproduced it alone.

That hook is tests/preload.ts's afterAll, whose sandbox removal (removeTestTempTree) retries synchronously on EPERM/EBUSY: 61 attempts with 14,850 ms of waits, which is the measured duration. Something in the process still held a directory in the sandbox open.

It was the local-credential observer. startClientRuntime starts it when it publishes (observeLocalCredentials), and its comment says it "lives exactly while this process serves". stopServing stops it, but recycleStandalone did not: it stopped the reporter, the route-intent watch and tick, the link supervisor and the listener, and left the observer and its fs.watch handles on directories under the config home running through the replacement handoff and until the process exited. A watched directory cannot be deleted on Windows. On macOS the observer refused the sandbox (the /var symlink parent fails assertParents), and on Linux inotify does not block deletion, so only Windows showed it.

The observer is now module state like the other active runtime parts (activeCredentialObservation), and the recycle stops it together with them, before the replacement handoff. The fixture records the stop and asserts it happened exactly once, before replacement.

Verification

  • Before the fix, on macOS with a real (non-symlink) TMPDIR so the observer actually starts: a probe around startLocalCredentialObservation reported {"started":1,"stopped":0} after recycleStandalone.
  • The new assertion fails on origin/dev (expect(...).toHaveLength(1), received 0) and passes with the fix.
  • bun test over the 12 files that exercise src/client/runtime.ts (client runtime, restart, link runtime, desktop-supervised restart, disconnect runtime, client start fence and owner e2e, link apply restart, service signal exit, route-intent runtime stop): 188 pass / 0 fail. bun run typecheck: exit 0.
  • NOT RUN: a native Windows runner (the next manual dev batch), and the full suite locally.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Summary by CodeRabbit

  • Bug Fixes
    • Improved runtime cleanup when a serving process stops, shuts down, or is recycled. Local credential monitoring now stops before a replacement process starts and is not started redundantly when a runtime is published.

…cles to standalone

recycleStandalone stopped the reporter, the route-intent watch and tick, the link
supervisor and the listener, but not the local-credential observer, which only
stopServing stopped. That observer is meant to live exactly while the process
serves; after a recycle it kept its fs.watch handles on directories under the
config home until the process exited, including across the replacement handoff.

On Windows a watched directory cannot be deleted, so the route-intent
runtime-stop fixture's sandbox removal retried for its whole 14.85s budget and
the preload's afterAll timed out (windows 5/14 in dev batches 43451726885 and
43483630535). On macOS the observer refused the /var symlink parent and on Linux
inotify does not block deletion, which hid the leak.

The observer is now module state like the other active runtime parts, and the
recycle stops it before the replacement handoff. The fixture asserts that.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 13, 2026 19:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T19:22:56.475212Z b8e334e PR opened
ℹ️ 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

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 13, 2026
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The runtime now shares the local-credential observation handle across publications and stops and clears the observer during standalone recycling, serving stop, and shutdown. The recycle test verifies that the observer stops once before the replacement runtime starts.

Changes: Credential observer lifecycle

Layer / File(s) Summary
Shared observer lifecycle and recycle validation
src/client/runtime.ts, tests/clients/route-intent-runtime-stop.test.ts
The runtime stores the observer handle at module scope and starts observation only when no observer is active. Recycling, stopServing, and shutdown stop and clear it. The recycle test checks that it stops exactly once before replacement.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: luvs01

Merge Risk: Minimal · up to b8e33

This change stops the local-credential observer when the runtime recycles, which should prevent Windows sandbox directory removal timeouts. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the local-credential observer is stopped when the runtime recycles to standalone. The raw summary confirms the observer is stopped and cleared when standalone recyclin…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the local-credential observer is stopped when the runtime recycles to standalone. The raw summary confirms the observer is stopped and cleared when standalone recycling begins, and the test verifies the stop happens exactly once before the replacement spawns. The title is specific, concise, and uses a conventional commit prefix. It does not describe anything absent from the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 696c7b5 and b8e334e.

Files selected for processing: 2

  • src/client/runtime.ts
  • tests/clients/route-intent-runtime-stop.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@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: b8e334e017

ℹ️ 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 thread src/client/runtime.ts
const replacementEnv = port && !serviceSupervised
? withSiblingMarker(standaloneRecycleEnv(process.env, disconnectedTokenFingerprint), issueSiblingHandoff)
: null;
activeCredentialObservation?.stop(); activeCredentialObservation = null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update the required architecture documentation with the lifecycle fix

This changes the client runtime's credential-observer ownership and recycle teardown, but the commit updates only the runtime and its test. structure/INDEX.md maps src/client/ to structure/runtime.md, structure/fallback-policy.md, and structure/clients/claude-desktop.md; the source instructions explicitly require every document listed for a changed area to be updated in the same change. Update those owned documents to reflect or cross-reference the observer lifecycle and its regression coverage so this change satisfies the repository's architecture-sync requirement.

AGENTS.md reference: src/AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer judgment: integrating into dev under the MAINTAINERS.md maintainer-integration exception, without a second maintainer approval. This is maintainer integration, not a self-approval.

Exact head b8e334e:

  • PR CI: every check on this head passed or was skipped by policy.
  • Fresh final review (gpt-6.1-terra, high) on this exact head: PASS, no blocking findings. Lifecycle reviewed: the recycle stops the observer before the replacement claims its lease; rollback republication starts a new one; signal shutdown still stops it; no second-runtime race found. structure/remote-link.md already says the client releases the observer before a restart hands over. Reviewer run: 133 pass / 0 fail on five runtime files, typecheck passed.
  • Red before the fix, verified by the author: the new assertion fails on origin/dev (toHaveLength(1), received 0); a probe with a non-symlink TMPDIR showed {"started":1,"stopped":0} after recycleStandalone. 188 pass / 0 fail over the 12 files exercising src/client/runtime.ts.
  • NOT RUN: native Windows execution; the next manual dev batch covers it.

Client lifecycle fix with no change to authentication, credentials or workflows; no outstanding maintainer change requests.

@lidge-jun
lidge-jun merged commit e3d4694 into dev Nov 13, 2026
33 checks passed
@lidge-jun
lidge-jun deleted the fix/dev-red6-recycle-credential-observer branch November 13, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant