Skip to content

Fix legacy retirement after listener handoff - #194

Merged
lawrencecchen merged 2 commits into
mainfrom
fix/legacy-stale-control-socket
Aug 7, 2026
Merged

lawrencecchen merged 2 commits into
mainfrom
fix/legacy-stale-control-socket

Conversation

@lawrencecchen

@lawrencecchen lawrencecchen commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the production continuity gate after a successful listener handoff.

  • quiesces an active legacy socket without stopping the service that owns held sessions
  • removes a stale legacy supervisor socket only after legacy units are inactive and disabled
  • keeps successful retirement runtime-masked and retry-safe
  • waits through normal systemd transition states
  • ignores normal shutdown timeout metadata while retaining real timeout detection

Regression history:

  • f2a6e69 adds the failing tests
  • 09ca5fa implements the fix

Verification:

  • go test ./...
  • exact-head local review clean on 09ca5fa

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The changes filter shutdown metadata from transport classification, preserve upstream timeout detection, and add guarded cleanup for inactive legacy control sockets. Retirement polling invokes cleanup after validating service and socket states.

Changes

Transport timeout classification

Layer / File(s) Summary
Explicit timeout detection
cmd/subrouter-transport-observer/golden_local_daemon.go
Shutdown termination messages are ignored. deadline exceeded adds the timeout category without duplicates.
Timeout classification regression coverage
cmd/subrouter-transport-observer/golden_runtime_continuity_test.go
Tests cover ignored shutdown metadata and singular, plural, and structured upstream timeout messages.

Legacy control socket cleanup

Layer / File(s) Summary
Guarded cleanup command
deploy/gcp/install-front-slots.sh, cmd/subrouter/deploy_scripts_test.go
The installer validates unit state, socket type, and kernel ownership before removal. The CLI command and mocked-systemd coverage are added.
Retirement flow integration
deploy/gcp/finalize-legacy-retirement.sh
Sampler adoption, drain polling, and retirement polling invoke cleanup when legacy units are inactive or absent.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Retirement as finalize-legacy-retirement.sh
  participant Installer as install-front-slots.sh
  participant Systemd as systemd
  participant SocketCheck as ss
  Retirement->>Installer: cleanup-stopped-legacy-control
  Installer->>Systemd: verify service and socket state
  Installer->>SocketCheck: check socket ownership
  SocketCheck-->>Installer: ownership result
  Installer-->>Retirement: cleanup result
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing legacy retirement after listener handoff.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/legacy-stale-control-socket

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.

@lawrencecchen
lawrencecchen force-pushed the fix/legacy-stale-control-socket branch 2 times, most recently from d2a1cb1 to f9b280d Compare August 7, 2026 05:12

@coderabbitai coderabbitai 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.

Actionable comments posted: 4

🤖 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 `@cmd/subrouter-transport-observer/golden_local_daemon.go`:
- Line 46: Update the assignment detection logic around notAssignment so it
skips horizontal whitespace between the key and delimiter before checking for
“=”, while preserving valid timeout parsing and rejecting malformed assignments.
Add a regression case covering “timeout = 10m0s” to ensure it is not recorded as
a transport timeout.

In `@cmd/subrouter/deploy_scripts_test.go`:
- Around line 2533-2544: The test helper run currently uses one enabled value
for both units, preventing coverage of the socket-unit branch in
cleanup-stopped-legacy-control. Update run to accept separate service and socket
enablement values, pass them to LEGACY_ENABLED and LEGACY_SOCKET_ENABLED, and
add a case with the service disabled and socket enabled that verifies the socket
remains.

In `@deploy/gcp/install-front-slots.sh`:
- Around line 713-718: Replace the is-enabled checks for both LEGACY_SERVICE and
LEGACY_SOCKET_SERVICE in deploy/gcp/install-front-slots.sh:713-718 with
list-unit-files --state=enabled queries, failing only when the requested unit is
explicitly reported as enabled and handling query failures separately. Apply the
same unit-state check in deploy/gcp/finalize-legacy-retirement.sh:186. Update
cmd/subrouter/deploy_scripts_test.go:2504-2510 to cover an explicit
query-failure state.
- Line 726: The socket ownership check in deploy/gcp/install-front-slots.sh at
lines 726-726 must query all Unix socket states rather than listening sockets
only; update the ss invocation while preserving ownership detection. In
cmd/subrouter/deploy_scripts_test.go at lines 2514-2518, update the ss mock to
reject listening-only queries for the target socket and add coverage for a
non-listening owned Unix socket.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d52c019b-f24d-4972-823c-18aabccee4ea

📥 Commits

Reviewing files that changed from the base of the PR and between 599e1c9 and f9b280d.

📒 Files selected for processing (5)
  • cmd/subrouter-transport-observer/golden_local_daemon.go
  • cmd/subrouter-transport-observer/golden_runtime_continuity_test.go
  • cmd/subrouter/deploy_scripts_test.go
  • deploy/gcp/finalize-legacy-retirement.sh
  • deploy/gcp/install-front-slots.sh

end := index + len(token)
beforeBoundary := index == 0 || !goldenIdentifierByte(text[index-1])
afterBoundary := end == len(text) || !goldenIdentifierByte(text[end])
notAssignment := end == len(text) || text[end] != '='

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reject whitespace-separated assignments.

Line 46 only rejects timeout=.... It accepts timeout = 10m0s and records a false transport timeout. This can fail normal shutdown flows when log formatting includes spaces around =.

Skip horizontal whitespace before checking for =. Add a regression case for timeout = 10m0s.

Proposed fix
-		notAssignment := end == len(text) || text[end] != '='
+		assignmentOffset := end
+		for assignmentOffset < len(text) &&
+			(text[assignmentOffset] == ' ' || text[assignmentOffset] == '\t') {
+			assignmentOffset++
+		}
+		notAssignment := assignmentOffset == len(text) || text[assignmentOffset] != '='
🤖 Prompt for 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.

In `@cmd/subrouter-transport-observer/golden_local_daemon.go` at line 46, Update
the assignment detection logic around notAssignment so it skips horizontal
whitespace between the key and delimiter before checking for “=”, while
preserving valid timeout parsing and rejecting malformed assignments. Add a
regression case covering “timeout = 10m0s” to ensure it is not recorded as a
transport timeout.

Comment thread cmd/subrouter/deploy_scripts_test.go Outdated
Comment thread deploy/gcp/install-front-slots.sh Outdated
Comment on lines +713 to +718
if systemctl is-enabled --quiet "${LEGACY_SERVICE}" >/dev/null 2>&1; then
die "refusing to remove the enabled legacy control socket"
fi
if systemctl is-enabled --quiet "${LEGACY_SOCKET_SERVICE}" >/dev/null 2>&1; then
die "refusing to remove the legacy control socket while ${LEGACY_SOCKET_SERVICE} is enabled"
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

if ! command -v systemctl >/dev/null; then
  echo "systemctl is unavailable on this host"
  exit 0
fi

set +e
systemctl is-enabled --quiet definitely-missing-subrouter-test.service
status=$?
set -e

printf 'systemctl is-enabled exit status for an unresolved unit: %s\n' "$status"

Repository: manaflow-ai/subrouter

Length of output: 197


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf 'Repository files matching targets:\n'
git ls-files | rg '(^deploy/gcp/install-front-slots\.sh$|^deploy/gcp/finalize-legacy-retirement\.sh$|^cmd/subrouter/deploy_scripts_test\.go$)' || true

printf '\nLine count targets:\n'
for f in deploy/gcp/install-front-slots.sh deploy/gcp/finalize-legacy-retirement.sh cmd/subrouter/deploy_scripts_test.go; do
  [ -f "$f" ] && wc -l "$f"
done

printf '\nRelevant shell lines:\n'
sed -n '690,730p' deploy/gcp/install-front-slots.sh
printf '\n'
sed -n '165,200p'部署/gcp/finalize-legacy-retirement.sh 2>/dev/null || sed -n '165,200p' deploy/gcp/finalize-legacy-retirement.sh
printf '\nRelevant test lines:\n'
sed -n '2480,2525p' cmd/subrouter/deploy_scripts_test.go

Repository: manaflow-ai/subrouter

Length of output: 6563


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf 'Repository files matching targets:\n'
git ls-files | rg '(^deploy/gcp/install-front-slots\.sh$|^deploy/gcp/finalize-legacy-retirement\.sh$|^cmd/subrouter/deploy_scripts_test\.go$)' || true

printf '\nLine count targets:\n'
for f in deploy/gcp/install-front-slots.sh deploy/gcp/finalize-legacy-retirement.sh cmd/subrouter/deploy_scripts_test.go; do
  [ -f "$f" ] && wc -l "$f"
done

printf '\nRelevant shell lines:\n'
sed -n '690,730p' deploy/gcp/install-front-slots.sh
printf '\n'
sed -n '165,200p' deploy/gcp/finalize-legacy-retirement.sh
printf '\nRelevant test lines:\n'
sed -n '2480,2525p' cmd/subrouter/deploy_scripts_test.go

Repository: manaflow-ai/subrouter

Length of output: 6563


🌐 Web query:

systemd systemctl is-enabled exit status invalid disabled documentation

💡 Result:

The systemctl is-enabled command checks whether the specified unit files are enabled [1][2]. Its exit status is determined by the following rules: 1. Exit Code 0: The command returns 0 if at least one of the specified unit files is considered enabled [3][1][4]. This includes states such as enabled, static, indirect, alias, and transient [1][2]. 2. Non-zero Exit Code: The command returns a non-zero value if none of the specified units are enabled (e.g., states like disabled, masked, or linked) [1][2][4]. Regarding the states mentioned: - Disabled: If a unit is in the disabled state, it generally results in a non-zero exit status (> 0) [1][2]. - Invalid (Bad): The is-enabled command does not return a specific bad state exit code [1][2]. If a unit file is invalid or another error occurs, the command typically prints an error message to standard error instead of returning a status associated with the "bad" state [1][2]. - Not Found: If a unit file does not exist, the command may return an exit code of 4 (in addition to printing "not-found" to standard output) [2]. Important Note on Multiple Arguments: The command's exit status logic remains the same even when multiple unit names are provided; it returns 0 as long as at least one of the units provided is enabled [4]. Documentation for the exact exit codes is available in the official systemctl(1) manual page [3][5].

Citations:


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf 'All references to legacy enablement checks and tests:\n'
rg -n 'is-enabled|LEGACY_ENABLED|LEGACY_SOCKET_ENABLED|cleanup_stopped_legacy_control|TestFrontSlotInstallerRemovesOnlyInactiveLegacyControlSocket|test.*systemctl.*is-enabled' deploy/gcp cmd/subrouter/deploy_scripts_test.go

printf '\nAll cleanup_stopped_legacy_control definitions/usages:\n'
rg -n 'cleanup_stopped_legacy_control' deploy/gcp cmd/subrouter/deploy_scripts_test.go

Repository: manaflow-ai/subrouter

Length of output: 5604


Check the unit file state instead of relying on systemctl is-enabled --quiet failure.

systemctl is-enabled --quiet returns non-zero for many non-enabled states, including errors such as not-found. Use systemctl list-unit-files --state=enabled <unit>, then confirm the result is absent; only fail when enabled is present. Apply the same check to both legacy units in deploy/gcp/install-front-slots.sh#L713-L718 and deploy/gcp/finalize-legacy-retirement.sh#L186; cover an explicit query-failure state in cmd/subrouter/deploy_scripts_test.go.

📍 Affects 3 files
  • deploy/gcp/install-front-slots.sh#L713-L718 (this comment)
  • deploy/gcp/finalize-legacy-retirement.sh#L186-L186
  • cmd/subrouter/deploy_scripts_test.go#L2504-L2510
🤖 Prompt for 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.

In `@deploy/gcp/install-front-slots.sh` around lines 713 - 718, Replace the
is-enabled checks for both LEGACY_SERVICE and LEGACY_SOCKET_SERVICE in
deploy/gcp/install-front-slots.sh:713-718 with list-unit-files --state=enabled
queries, failing only when the requested unit is explicitly reported as enabled
and handling query failures separately. Apply the same unit-state check in
deploy/gcp/finalize-legacy-retirement.sh:186. Update
cmd/subrouter/deploy_scripts_test.go:2504-2510 to cover an explicit
query-failure state.

Comment thread deploy/gcp/install-front-slots.sh
@lawrencecchen
lawrencecchen force-pushed the fix/legacy-stale-control-socket branch 7 times, most recently from 578251c to 310a0b9 Compare August 7, 2026 06:26
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
cmd/subrouter-transport-observer/golden_local_daemon.go (1)

36-38: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add direct coverage for deadline exceeded.

The supplied regression test covers "timeout", "timeouts", and "timeout=true", but not the new "deadline exceeded" branch. Add a case that asserts local_daemon_transport_issue_timeout.

🤖 Prompt for 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.

In `@cmd/subrouter-transport-observer/golden_local_daemon.go` around lines 36 -
38, Add a regression-test case for input containing “deadline exceeded” without
an existing timeout marker, and assert that the result includes
local_daemon_transport_issue_timeout. Keep the existing timeout, timeouts, and
timeout=true cases unchanged.
🤖 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.

Nitpick comments:
In `@cmd/subrouter-transport-observer/golden_local_daemon.go`:
- Around line 36-38: Add a regression-test case for input containing “deadline
exceeded” without an existing timeout marker, and assert that the result
includes local_daemon_transport_issue_timeout. Keep the existing timeout,
timeouts, and timeout=true cases unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5e3e2399-3d54-4b27-aab9-777b6dae59aa

📥 Commits

Reviewing files that changed from the base of the PR and between 918eadc and 310a0b9.

📒 Files selected for processing (5)
  • cmd/subrouter-transport-observer/golden_local_daemon.go
  • cmd/subrouter-transport-observer/golden_runtime_continuity_test.go
  • cmd/subrouter/deploy_scripts_test.go
  • deploy/gcp/finalize-legacy-retirement.sh
  • deploy/gcp/install-front-slots.sh
🚧 Files skipped from review as they are similar to previous changes (3)
  • cmd/subrouter/deploy_scripts_test.go
  • cmd/subrouter-transport-observer/golden_runtime_continuity_test.go
  • deploy/gcp/finalize-legacy-retirement.sh

@lawrencecchen
lawrencecchen force-pushed the fix/legacy-stale-control-socket branch 5 times, most recently from 8d214f7 to 3e829d0 Compare August 7, 2026 06:57
@lawrencecchen
lawrencecchen force-pushed the fix/legacy-stale-control-socket branch from 3e829d0 to ede46db Compare August 7, 2026 07:05
@lawrencecchen
lawrencecchen force-pushed the fix/legacy-stale-control-socket branch from ede46db to 09ca5fa Compare August 7, 2026 07:10
@lawrencecchen
lawrencecchen merged commit c625e7b into main Aug 7, 2026
7 checks passed
@lawrencecchen
lawrencecchen deleted the fix/legacy-stale-control-socket branch August 7, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant