Skip to content

fix(update): preserve service repair on scan failure - #1375

Merged
Wibias merged 3 commits into
lidge-jun:devfrom
luvs01:agent/fix-update-service-scan
Aug 10, 2026
Merged

fix(update): preserve service repair on scan failure#1375
Wibias merged 3 commits into
lidge-jun:devfrom
luvs01:agent/fix-update-service-scan

Conversation

@luvs01

@luvs01 luvs01 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Preserve the service-refresh path when the post-reclaim listener scan is inconclusive.
  • Treat only a successful empty PID scan as proof that there are no live holders.
  • Keep injected list-only test seams compatible by treating their result as a successful scan, and add a regression for unavailable listener tools.

Verification

  • Bun 1.3.14: bun test tests/update-job.test.ts — 54 passed.
  • Bun 1.3.14: focused listener-scan regression — 1 passed.
  • bun run typecheck — passed.
  • bun run privacy:scan — passed.
  • git diff --check HEAD^ HEAD — passed.
  • The previous exact head completed full GitHub CI successfully; subsequent review-only test refinements retained the same production patch.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • No documentation change is required for this recovery-path correction.
  • The branch is based on the latest dev.

Review readiness checklist

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

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes

    • Improved service restarts when listener detection fails, preventing valid installations from being incorrectly skipped.
    • Enhanced reclaim handling by checking all available listeners before deciding whether a service can start.
    • Ensured repair actions continue when port waiting or listener scanning is unavailable.
  • Tests

    • Added regression coverage for successful service restarts when listener scanning is unavailable.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 78c6a1f6-dc44-4e4a-b2fa-bb002daa6011

📥 Commits

Reviewing files that changed from the base of the PR and between 33558af and 3ee2aa6.

📒 Files selected for processing (1)
  • tests/update-job.test.ts

📝 Walkthrough

Walkthrough

The restart flow now distinguishes failed listener scans from confirmed empty scans. Failed scans preserve service repair. A regression test verifies that the repair command runs after listener inspection fails.

Changes

Service restart recovery

Layer / File(s) Summary
Listener scan recovery and regression coverage
src/update/job.ts, tests/update-job.test.ts
At lines 1137–1146, the restart path uses ListenPidScan results. It applies the no-live-holder fallback only after a successful scan confirms no live listeners. The test at lines 449–486 verifies one repair command and no reclaim-timeout skip when scanning fails.

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

Possibly related PRs

Suggested reviewers: ingwannu, lidge-jun, wibias

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes preserving service repair when listener scanning fails, which matches the main changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 9, 2026
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

✅ READY

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

Review readiness checklist

  • ✅ All CI tests are green on my local testing.
  • ✅ I pushed my PR to the latest dev commit.
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

4/4 boxes ticked.

This pull request has been marked Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently. If no CodeRabbit review appears, comment @coderabbitai review to request one.
Maintainers notified: @lidge-jun @Ingwannu @Wibias

Wibias commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Please rebase this PR onto the latest dev (e8ce2b93dd3ef8074d96dee407704c5dc06e2699) before merge, then rerun the exact-head CI checks.

@luvs01
luvs01 force-pushed the agent/fix-update-service-scan branch from 8e9b7ad to fbf4a7f Compare August 9, 2026 23:25
@Wibias
Wibias marked this pull request as ready for review August 9, 2026 23:45
@luvs01

luvs01 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/update-job.test.ts`:
- Around line 465-476: Add a spawnStart stub to the restartAfterUpdateForTests
options in the regression test, ensuring the direct-start fallback cannot launch
production processes or poll real OS state. Keep the stub deterministic and
aligned with the existing spawnStart seam in restartAfterUpdate.
- Around line 471-477: Update the test setup around runService in the relevant
update-job test to capture its args, then assert the invocation includes the
"repair" argument in addition to verifying serviceRuns is 1. Preserve the
existing probeProxy behavior and validate the command executed by the restart
path.
- Around line 451-464: Update the UpdateJobState fixture in the test around the
job object to include the required releaseNotesUrl property, using an empty
string so the persisted job matches the current schema.
🪄 Autofix

❌ Autofix failed (check again to retry)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c21e7f30-5c21-4251-9f1c-bf9e6fcd4756

📥 Commits

Reviewing files that changed from the base of the PR and between d517161 and fbf4a7f.

📒 Files selected for processing (2)
  • src/update/job.ts
  • tests/update-job.test.ts

Comment thread tests/update-job.test.ts
Comment thread tests/update-job.test.ts Outdated
@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 00:06
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

An unexpected error occurred while generating fixes: Not Found - https://docs.github.com/rest/git/refs#get-a-reference

@luvs01
luvs01 force-pushed the agent/fix-update-service-scan branch from fbf4a7f to afa26aa Compare August 10, 2026 00:31
@Wibias
Wibias marked this pull request as ready for review August 10, 2026 00:39
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Rate Limit Exceeded

@github-actions[bot] have exceeded the limit for the number of chat messages per hour. Please wait 12 minutes and 40 seconds before sending another message.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Rate Limit Exceeded

@github-actions[bot] have exceeded the limit for the number of chat messages per hour. Please wait 5 minutes and 42 seconds before sending another message.

@luvs01
luvs01 force-pushed the agent/fix-update-service-scan branch from afa26aa to 33558af Compare August 10, 2026 01:11
@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 01:11
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== Pull request metadata =='
gh pr view 1375 --repo lidge-jun/opencodex \
  --json number,state,isDraft,baseRefName,baseRefOid,headRefName,headRefOid,mergeable,statusCheckRollup \
  --jq '{number,state,isDraft,baseRefName,baseRefOid,headRefName,headRefOid,mergeable,statusCheckRollup:[.statusCheckRollup[]|{name,conclusion,status}]}'

echo
echo '== Pull request diff =='
gh pr diff 1375 --repo lidge-jun/opencodex -- src/update/job.ts tests/update-job.test.ts

echo
echo '== Source outline =='
ast-grep outline src/update/job.ts --items all --view expanded

echo
echo '== Test outline =='
ast-grep outline tests/update-job.test.ts --items all --view expanded

Length of output: 1669


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== Changed-file patches on current PR head =='
gh api 'repos/lidge-jun/opencodex/pulls/1375/files?per_page=100' \
  --jq '.[] | "===== \(.filename) =====\n\(.patch // "(no textual patch)")"'

echo
echo '== Current source structure =='
ast-grep outline src/update/job.ts --items all --view expanded

echo
echo '== Current test structure =='
ast-grep outline tests/update-job.test.ts --items all --view expanded

echo
echo '== Listener-scan references and contracts =='
rg -n -C 5 --glob '!node_modules/**' --glob '!dist/**' \
  'listListenPids|listen.*Pid|Listener.*scan|listener.*scan|waitForPort|reclaim' \
  src tests

echo
echo '== Current PR-head checks =='
gh pr checks 1375 --repo lidge-jun/opencodex --json name,state,link \
  --jq '.[] | {name,state,link}'

Length of output: 128163


@github-actions[bot] I reviewed the current PR head 33558af5c2abcf8d0f0082ed273dfb949561b45e.

I found no correctness issues in the changed code.

src/update/job.ts now skips service reinstall only when ListenPidScan.ok is true and the successful scan contains no live PID. A failed scan leaves skipServiceInstall false. The service repair path then runs.

tests/update-job.test.ts covers the failed-scan case. It verifies that service repair runs and that the direct-start fallback message is not logged.

The readiness-gate record is stale. It identifies completed head afa26aa96a95a81c66703b3b6d51accf93d3f168, not the current head. The current quality-gate checks are successful, but the CodeRabbit check is still pending.

You are interacting with an AI system.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/update-job.test.ts`:
- Line 466: Update the call to updateJobPath in the test setup to match its
declared zero-argument signature, removing the job.id argument while preserving
the existing writeFileSync behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 17754528-bd4d-4179-8f21-95652f81e65c

📥 Commits

Reviewing files that changed from the base of the PR and between fbf4a7f and 33558af.

📒 Files selected for processing (1)
  • tests/update-job.test.ts

Comment thread tests/update-job.test.ts Outdated
@luvs01
luvs01 marked this pull request as ready for review August 10, 2026 01:18
@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 01:21
@luvs01
luvs01 marked this pull request as ready for review August 10, 2026 01:22
@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 01:22
@github-actions
github-actions Bot marked this pull request as ready for review August 10, 2026 01:28
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

repo="lidge-jun/opencodex"
pr="1375"
previous_head="33558af5c2abcf8d0f0082ed273dfb949561b45e"

echo '== PR metadata and checks =='
gh pr view "$pr" --repo "$repo" \
  --json headRefOid,baseRefOid,mergeable,statusCheckRollup,commits \
  --jq '{
    headRefOid,
    baseRefOid,
    mergeable,
    commits: [.commits[] | {oid: .oid, messageHeadline: .messageHeadline}],
    checks: [.statusCheckRollup[] | {name, status, conclusion}]
  }'

echo
echo '== Files changed since the previously reviewed head =='
git diff --name-status "$previous_head"...HEAD

echo
echo '== Current PR patches =='
gh api "repos/$repo/pulls/$pr/files?per_page=100" \
  --jq '.[] | "===== \(.filename) =====\n\(.patch // "(no textual patch)")"'

echo
echo '== Source and test structure =='
ast-grep outline src/update/job.ts --items all --view expanded
ast-grep outline tests/update-job.test.ts --items all --view expanded

echo
echo '== Listener-scan and service-repair context =='
rg -n -C 8 --glob '!node_modules/**' --glob '!dist/**' \
  'listListenPids|ListenPidScan|waitForPort|skipServiceInstall|reclaim|service.*install|service.*repair' \
  src/update/job.ts tests/update-job.test.ts

Length of output: 76860


🏁 Script executed:

#!/bin/bash
set -euo pipefail

repo="lidge-jun/opencodex"
pr="1375"
head="3ee2aa6b02e599092cb7865cca489164687872cd"

echo '== Final commit patch =='
git show --format=fuller --find-renames --find-copies "$head" -- tests/update-job.test.ts

echo
echo '== Production control-flow range =='
sed -n '1107,1210p' src/update/job.ts

echo
echo '== Regression test range =='
sed -n '449,486p' tests/update-job.test.ts

echo
echo '== Checks attached to the current head =='
gh api "repos/$repo/commits/$head/check-runs?per_page=100" \
  --jq '.check_runs[] | {
    name,
    status,
    conclusion,
    started_at,
    completed_at,
    details_url,
    head_sha
  }'

echo
echo '== Current head commit statuses =='
gh api "repos/$repo/commits/$head/status" \
  --jq '{sha, state, statuses: [.statuses[] | {context, state, target_url, updated_at}]}'

echo
echo '== Ready-gate comment =='
gh pr view "$pr" --repo "$repo" --comments --json comments \
  --jq --arg head "$head" \
  '[.comments[] | select(.body | contains("opencodex-pr-gate-state") and contains($head)) | {
    author: .author.login,
    createdAt,
    body
  }]'

Length of output: 13140


@github-actions[bot] Review complete for current head 3ee2aa6b02e599092cb7865cca489164687872cd.

I found no correctness issues.

src/update/job.ts Lines 1137-1150 preserves service repair when the listener scan fails. A failed scan sets liveAfter to null. The service-reinstall skip runs only after a successful empty scan.

tests/update-job.test.ts now calls updateJobPath() with its declared zero-argument signature. The regression test still verifies that service repair runs and that the reclaim-timeout skip log is absent.

The current head has a successful enforce-target check. Earlier failed enforce-target runs are historical entries. The CodeRabbit status was pending when I checked it.

You are interacting with an AI system.

@Wibias
Wibias merged commit cde59ec into lidge-jun:dev Aug 10, 2026
25 of 32 checks passed

Wibias commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Thanks @luvs01! Appreciate the focused service-repair fix, deterministic regression coverage, and the careful follow-up on the review findings. Merged. 🙏

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

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants