Skip to content

fix(shannon-worker): insert each Shannon helper independently#31

Open
peteromallet wants to merge 1 commit into
mainfrom
fix/shannon-helper-independent-gates
Open

fix(shannon-worker): insert each Shannon helper independently#31
peteromallet wants to merge 1 commit into
mainfrom
fix/shannon-helper-independent-gates

Conversation

@peteromallet
Copy link
Copy Markdown
Owner

Bug

The Shannon entrypoint patcher in _ensure_shannon_parent_timeout_control
defined three TypeScript helpers (isRootProcess, rootSafeClaudeArgs,
maybeSendStartupEnterKeys) as one multi-line blob and gated insertion of
the entire blob on whether rootSafeClaudeArgs was already present in the
file.

That gate fails on a partially-patched entrypoint. If an earlier megaplan
revision had injected only the first two helpers (no
maybeSendStartupEnterKeys), a newer megaplan would see
rootSafeClaudeArgs already present and skip the entire blob -- leaving
maybeSendStartupEnterKeys undefined. The downstream patch that inserts
void maybeSendStartupEnterKeys(tmuxSession); runs independently and
still spliced the call site, so the patched entrypoint compiled but
exploded at runtime with a Bun ReferenceError.

Megaplan surfaced this as Shannon readiness probe failed with exit code 1.

Fix

Split the helper blob into three independent strings and gate each on its
own unique signature substring. Insertion order is preserved by inserting
in reverse before the same buildClaudeArgs anchor, so a fully
unpatched entrypoint still ends up with isRootProcess ->
rootSafeClaudeArgs -> maybeSendStartupEnterKeys ->
buildClaudeArgs, while a partially-patched entrypoint only gets the
missing helper(s) inserted.

Test plan

  • pytest tests/test_workers.py -k shannon -- existing patcher test
    still passes (full unpatched entrypoint).
  • New test_shannon_worker_heals_partially_patched_entrypoint
    passes -- starts from an entrypoint that already contains
    isRootProcess and rootSafeClaudeArgs (and the dangling
    void maybeSendStartupEnterKeys(tmuxSession); call site) and asserts
    the patch pass now inserts the missing definition without duplicating
    the present helpers.
  • Pre-existing test_run_shannon_step_passes_prompt_with_print_flag
    failure is unrelated to this change (fails on main too).

Scope note

The Shannon helper-patcher infrastructure plus a related non-root Shannon
runtime feature (MEGAPLAN_SHANNON_DROP_ROOT / nonroot home seeding)
and a defensive _normalize_worker_payload defaulting tweak were
already staged in the working tree but not yet committed on main -- so
this PR also carries those in-flight files. The gate-fix patch sits on
top of that infrastructure; cherry-picking only the gate refactor would
modify code that doesn't yet exist on main.

The Shannon entrypoint patcher gated the entire helper blob
(isRootProcess + rootSafeClaudeArgs + maybeSendStartupEnterKeys) on
rootSafeClaudeArgs being absent. When an earlier patch had inserted
only isRootProcess+rootSafeClaudeArgs, the next patch saw the gate
satisfied and skipped the whole blob -- leaving maybeSendStartupEnterKeys
undefined and the call site dangling. Result was a Bun ReferenceError
at runtime and "Shannon readiness probe failed with exit code 1".

Refactor each helper into its own gate-and-insert block so a
partially-patched entrypoint heals on the next patch pass. Add
regression test covering the partial-patch case.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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