Skip to content

Worker-orbit maintenance: unforgeable triage dedup, broker self-reap, review-engine suite re-pin - #82

Merged
SSFSKIM merged 9 commits into
mainfrom
dp26-59-56-maintenance
Aug 22, 2026
Merged

SSFSKIM merged 9 commits into
mainfrom
dp26-59-56-maintenance

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Three reliability fixes in the same worker orbit as PR #80.

dp#59 — triaging-feedback: the idempotency marker was forgeable

GitHub's --search is full-text, so a forged <!-- feedback:<id> --> quoted inside another ticket — in the fenced raw feedback, or in a prompt-injected diagnosis body — matched another row's duplicate lookup and silently dropped that feedback as already-ticketed. findExisting now treats the search as candidate collection only: each candidate is re-fetched and trusted only when the marker sits at the body/comment footer — the one position no user-derived text can reach, since registerTicket and commentOnIssue always stamp the marker as the artifact's last line. Footer verification also defends against injected markers outside the fence, which fence-stripping could not. Fail-closed behavior extends to the verification fetch. 5 new vitest cases; 113/113 green, tsc clean.

Fixes #59

dp#56 — codex-companion: broker/app-server pairs self-reap after 30 idle minutes

A broker is workspace-scoped and spawned detached, so a session dying mid-run — or a review worktree being deleted — orphaned a live broker + codex app-server pair forever (19h55m pairs observed). The issue's preferred pid-file sweep can't reach these: their sockets are healthy, and whether anyone still wants a broker is knowledge only it has — a client holds its connection open for as long as it is being served, and the OS closes that socket the instant the client dies. So the broker reaps itself: no client connection for CODEX_COMPANION_BROKER_IDLE_TIMEOUT_MS (default 30 min; unparseable falls back to the default so a typo can't resurrect the leak; explicit 0 disables) ⇒ clean shutdown taking the app-server child, socket, and pid file along. Same-workspace dead-socket records were already swept by ensureBrokerSession; the two mechanisms compose. 3 new node:test cases (idle reap, held-connection service, disabled reaper); full runtime suite 111/111. SKILL.md/jobs.md leak prose updated to match.

Fixes #56

dp#26 (delegated judgment) — the review-engine suite is re-pinned at the seam the engine owns

The suite was dead without a system node (rc=127 before the first assertion) and its stub codex spoke the retired codex exec review transport while with-effort.mjs drives an app-server thread. Since review-engine.sh is live and load-bearing for the qa-loops loop on main, the suite is rewritten rather than deleted — but the pin moves to the surface the engine actually controls: it now stubs node and asserts the with-effort.mjs command line the engine composes (verb routing, defaults, the lens contract), the env recipe, rc mapping, and the fail-closed sandbox check. The thread protocol stays pinned where it belongs, in tests/codex-companion/ against the protocol-speaking fake codex — so a future transport change can no longer rot this suite. 34 assertions, zero real-node dependency; 3 engine mutations each fail exactly their discriminating asserts.

Validation

  • skills/triaging-feedback: npx vitest run 113 passed, npx tsc --noEmit clean
  • tests/codex-companion/run-codex-companion-tests.sh 111 passed
  • tests/qa-loops/test-review-engine.sh all green (34); mutation-checked ×3
  • tests/qa-loops/test-review-dispatch.sh, test-skill-entrypoint.sh, test-bootstrap-parity.sh green
  • scripts/lint-shell.sh clean
  • v7.61.0 via scripts/bump-version.sh

…artifact footer decides

GitHub's --search is full-text, so a forged <!-- feedback:<id> --> quoted
inside another ticket (fenced raw feedback, or an injected diagnosis body)
matched another row's duplicate lookup and silently dropped that feedback
as already-ticketed (dp#59). findExisting now re-fetches each candidate
and only trusts a marker sitting at the body/comment footer — the one
position no user-derived text can reach, since registerTicket and
commentOnIssue always stamp the marker as the artifact's last line.
A broker is workspace-scoped and spawned detached, so a session dying
mid-run — or a review worktree being deleted — orphaned a live broker +
codex app-server pair forever: the socket stays healthy and nobody who
can reach that workspace's broker.json exists anymore (19h55m pairs
observed live, dp#56). No outside sweep can reap those safely; whether
anyone still wants a broker is knowledge only it has, since a client
holds its connection open for as long as it is being served and the OS
closes that socket the instant the client dies. So the broker shuts
itself down — app-server child, socket and pid file included — after
CODEX_COMPANION_BROKER_IDLE_TIMEOUT_MS (default 30min, 0 disables)
with no client connection.
… owns

The suite was dead on any machine without a system node (the PATH scrub
that hides the real codex also hid node, rc=127 before the first
assertion), and past that its stub codex still spoke the retired
`codex exec review` transport while with-effort.mjs drives an
app-server thread — assertions against a surface the engine no longer
touches (dp#26). Rewritten to stub node itself: the pin is now the
with-effort.mjs command line the engine composes (verb routing,
defaults, the lens contract), its env recipe, rc mapping, and the
fail-closed sandbox check — with no dependency on a real node or the
thread protocol, which tests/codex-companion pins separately against a
protocol-speaking fake codex. 34 assertions; three engine mutations
(drop --wait, disable the sandbox fail-closed, invert lens precedence)
each fail exactly their discriminating asserts.
@SSFSKIM SSFSKIM mentioned this pull request Aug 21, 2026
9 tasks done

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

ℹ️ 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 +160 to +164
idleTimer = setTimeout(async () => {
if (sockets.size > 0) {
return;
}
await shutdown(server);

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 Stop accepting sockets before awaiting app-server shutdown

If a client connects after this zero-socket check but while shutdown() is awaiting appClient.close(), the listening server still accepts it; the broker then closes the app-server underneath that client and server.close() waits for the newly accepted socket, so an invocation arriving at the idle-timeout boundary can receive broken service and prevent the broker from exiting. Close the listener or mark the broker as shutting down before the first asynchronous shutdown step.

Useful? React with 👍 / 👎.

if (sockets.size > 0) {
return;
}
await shutdown(server);

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 Clear the persisted broker session when self-reaping

After the idle timer calls shutdown(), it removes the socket and PID file but leaves the workspace's broker.json. A later work verb heals this through ensureBrokerSession(), but setup calls getCodexAuthStatus() with reuseExistingBroker and connects directly to the stale endpoint, so every normally reaped broker can make setup report a false authentication failure and suggest logging in again until another work verb runs. Remove or invalidate the persisted broker session as part of idle shutdown, or make diagnostic consumers probe and clear stale sessions.

Useful? React with 👍 / 👎.

Comment on lines +58 to +62
const value = Number(raw);
if (!Number.isFinite(value)) {
return DEFAULT_IDLE_TIMEOUT_MS;
}
return value > 0 ? value : 0;

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 Reject idle timeouts above Node's timer limit

When CODEX_COMPANION_BROKER_IDLE_TIMEOUT_MS is set above 2,147,483,647 ms—for example, a plausible 30-day retention value—this validation accepts it, but Node clamps the setTimeout delay to 1 ms with a TimeoutOverflowWarning. The broker then self-reaps almost immediately instead of honoring the requested long timeout, making normal clients race a continuously disappearing broker; reject or safely cap values outside Node's supported timer range.

Useful? React with 👍 / 👎.

Comment thread tests/qa-loops/test-review-engine.sh Outdated
Comment on lines +202 to +205
rc=0; PATH="$NODE_ONLY:/usr/bin:/bin" "$ENGINE" --base origin/main --out "$TEST_ROOT/out.txt" 2>/dev/null || rc=$?
assert_equals "$rc" "127" "missing codex CLI exits 127"
rc=0; PATH="$CODEX_ONLY:/usr/bin:/bin" "$ENGINE" --base origin/main --out "$TEST_ROOT/out.txt" 2>/dev/null || rc=$?
assert_equals "$rc" "127" "missing node exits 127"

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 Exclude system binaries from missing-dependency tests

On hosts where Node is installed as /usr/bin/node—a common Linux layout—the purported missing-node invocation still finds the real binary because /usr/bin:/bin remains in PATH, so the engine proceeds instead of returning 127 and this acceptance suite fails for reasons unrelated to the change. The missing-codex case has the same flaw when Codex is system-installed; build a minimal test PATH containing only the shell utilities and the one intended stub.

Useful? React with 👍 / 👎.

… trailing meta block

The footer check added for dp#59 required the artifact body to END with our
`<!-- feedback:<id> -->` marker, but the board renders its own meta block AFTER
the body (_board.py compose_body), so any ticket carrying a park note or a
spawned-by edge ends with `<!-- board:meta … -->` instead. findExisting refused
those genuine tickets, and a retry after a failed DB writeback filed a duplicate.

findExisting now strips one trailing board:meta block before the endsWith check.
The regex refuses to cross a closer line, so a quoted fake block inside the prose
cannot swallow the real footer — only the board's own trailer is ever removed.
…s new clients mid-shutdown

The idle self-reap left the workspace's broker.json behind, and nothing that
reads that record probes the endpoint: `status` kept reporting a live shared
session and `setup`'s auth path dialled the dead broker and blamed auth, until
some later work verb's ensureBrokerSession swept it. Shutdown now deletes the
record, but only when it still names this broker — ensureBrokerSession may have
already replaced it with a successor's.

The listener also kept accepting while shutdown awaited appClient.close(), so a
client arriving after the idle timer's empty-socket check got a connection that
was in no end-loop, reached a closing app client, and could stall server.close.
Such a connection is now destroyed on arrival, which the caller already handles
as a probe failure and answers by respawning.
Both cases kept /usr/bin and /bin on the PATH, so on any host that ships the
dependency they claim is absent — a Debian-family /usr/bin/node, a
system-installed codex — the engine would find it and the case would assert
nothing about the preflight it exists to pin.

Each restricted directory is now the entire PATH, holding only the one stub
being kept plus a symlink to the real bash. That is sufficient because both
preflights are `command -v` builtins and both 127 exits happen before the engine
runs any external command; bash is present only so the engine's
`#!/usr/bin/env bash` shebang can resolve.
@SSFSKIM

SSFSKIM commented Aug 21, 2026

Copy link
Copy Markdown
Owner Author

Independent review round 1 (codex native, gpt-5.6-sol) — 4 findings, all verified real, all adopted

  • P1 sideEffects.ts — footer verification rejected genuine parked tickets: board-register renders --note/--spawned-by meta as a trailing <!-- board:meta --> block after the feedback marker, so a retry after a DB-writeback failure would have filed a duplicate. Fixed in ecd69641: one trailing board-meta block is stripped before the endsWith check. The strip regex uses a tempered interior ((?:(?!\n-->)[\s\S])*) rather than a lazy dot — a lazy middle anchored at $ binds the leftmost opener, which in the forgery case is the fake block quoted inside the fence, and would have re-admitted the forgery. Forgery-safety holds: clean_meta refuses meta values carrying the opener token, and no user-derived text can follow the genuine marker.
  • P2 broker idle reap left the durable broker.json behind — status reported a live shared session and setup dialed the dead endpoint until a work verb swept it. Fixed in 0dca43b7: shutdown clears the workspace record iff it still names this broker's endpoint (never a successor's).
  • P2 clients accepted mid-shutdown could initialize against a closing app client or stall server.close indefinitely. Same commit: a shuttingDown flag destroys new sockets; the client sees a failed probe, which ensureBrokerSession answers by respawning.
  • P2 the suite's missing-dependency cases kept /usr/bin on PATH, so Debian's /usr/bin/node would have satisfied the "missing node" case. Fixed in cddc50a9: each case runs with a fully hermetic PATH (real-bash symlink + the single kept stub — both 127 exits happen before any external command runs).

Re-verified post-fix: triaging-feedback vitest 115/115 + tsc clean; codex-companion runtime suite 113/113 (incl. 2 new broker-record cases); review-engine suite all green (34); discriminance re-checked with the fixes reverted.

…ailer opener

Stripping a trailing board:meta block meant first FINDING its opener, and that is
the ambiguity _board.py's meta_match exists to resolve. Quoted prose that leaves
a bare `<!-- board:meta` line unclosed gave the leftmost opener a match running
through the genuine feedback marker to the real trailer's closer, so the strip
deleted the marker itself and a genuine ticket was refused.

The check now anchors on the only trustworthy position, the last occurrence of
the stamp, and asks whether everything after it is nothing but whitespace, at
most one well-formed meta block, and end of string. Openers are never hunted, so
unclosed, quoted, and legacy-nested ones cost nothing. A forged stamp in user
content always has more prose behind it and still fails.

The candidate search also carried gh's silent default of 30 rows: forged quote
tickets can be minted one per feedback submission, and a genuine artifact ranked
past the first page left the loop validating only forgeries. It now asks for 100.
…inst a boot-captured state path

Refusing new connections did not make the broker undiscoverable: a prober's
transport-level connect can succeed before the shuttingDown destroy lands, and
the socket file and the record were only removed after appClient.close() and
server.close(). ensureBrokerSession could therefore hand a caller a dying broker
and the verb would fail instead of respawning. Both removals now happen first,
before anything that awaits.

The record clear also resolved its own path at reap time. The state directory is
derived from the workspace root, so a workspace deleted mid-run — a review
worktree, the case that produced these orphans — hashed elsewhere by then and the
stale broker.json was never cleared. The path is captured at boot instead, which
is why lib/broker-lifecycle.mjs now exports resolveBrokerStateFile.

A sibling review finding asked for an atomic compare-and-delete on the record;
declined, with the reasoning recorded at the call site.
@SSFSKIM

SSFSKIM commented Aug 22, 2026

Copy link
Copy Markdown
Owner Author

Independent review round 2 (codex native, gpt-5.6-sol, on the round-1-fixed branch) — 5 findings: 4 adopted, 1 declined

  • Adopted sideEffects.ts — the round-1 trailer strip still over-stripped on an unmatched quoted <!-- board:meta opener (no closer of its own): the tempered match ran from the quoted opener through the genuine marker to the real trailer's closer, rejecting the genuine ticket (reproduced in node before fixing). dc9bd73c replaces opener-hunting entirely: the check anchors on the stamp's last occurrence and requires the tail after it to match "whitespace + at most one well-formed board-meta block + end". That sidesteps the whole opener-ambiguity class _board.py::meta_match exists to solve, and also handles legacy-nested meta values. Discriminance: the old strip version fails the new unclosed-opener test.
  • Adopted — a probe's transport-level connect can succeed before the shuttingDown destroy lands, handing a caller the dying broker. 38b2a734 reorders shutdown: the socket path is unlinked and the record withdrawn before any await, so probes fail immediately and ensureBrokerSession respawns.
  • Adopted — a workspace deleted before the reap (a review worktree) resolves to a different state dir at shutdown time, so the record was never cleared. Same commit: the state-file path is captured at boot (resolveBrokerStateFile now exported) and shutdown compares/unlinks against that path directly. Discriminance: resolving at reap time fails the new deleted-workspace test.
  • Adopted — gh issue list silently caps at 30 rows; with 30+ forged-quote tickets the genuine artifact could rank off-page and the loop would validate only forgeries. dc9bd73c adds --limit 100 (asserted in tests; past that scale the failure degrades to a visible duplicate, not a silent drop).
  • Declined — atomic compare-and-delete on broker.json: the record has no lock regime anywhere in the runtime (ensureBrokerSession's own load/save is unlocked too), the withdraw now happens at decision time before any await, and a successor would need its entire teardown → respawn → save pipeline to land between two adjacent syscalls. Rationale recorded as a comment at the call site.

Extra probe beyond the review: a forged feedback: marker planted inside a genuine park note's meta value (which clean_meta does not filter) — the tail grammar rejects it, since the text after that stamp is \n-->, not a well-formed tail.

Re-verified at HEAD: triaging-feedback vitest 117/117 + tsc clean; codex-companion runtime suite 114/114; review-engine suite all green; shellcheck clean.

@SSFSKIM
SSFSKIM merged commit 34acf70 into main Aug 22, 2026
@SSFSKIM
SSFSKIM deleted the dp26-59-56-maintenance branch August 22, 2026 13:13
SSFSKIM added a commit that referenced this pull request Oct 16, 2026
sminos suite: pass from a symlinked checkout path (Arkho #82, 7.160.2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant