Skip to content

skills(running-in-ci): end the turn only when work is shipped - #661

Merged
max-sixty merged 2 commits into
mainfrom
skills/ship-before-waiting-27054491689
Jun 7, 2026
Merged

max-sixty merged 2 commits into
mainfrom
skills/ship-before-waiting-27054491689

Conversation

@tend-agent

@tend-agent tend-agent commented Jun 6, 2026 •

Copy link
Copy Markdown
Collaborator

Three sessions over a ~17-hour window did meaningful code work for a maintainer ask, then silently failed to ship anything because each one emitted end_turn while a run_in_background: true pre-merge gate was still pending. The harness did not resume — none of the runs ever subscribed to a task-notification wakeup (one didn't call Monitor, two more got InputValidationError on a deferred-tool schema race and never retried). Each occurrence leaves a visibly unanswered maintainer ask: branch never pushed, no commit, no comment, no signal the work happened.

This reframes the rule after maintainer review (#661 (comment)). The first cut narrowed it to "ship the deliverable before any long wait" under PR Creation; the failure mode generalises beyond PR creation to any case where end_turn fires while a maintainer-visible deliverable is staged but un-shipped — comment posting, follow-up commits, inline replies, anywhere a run_in_background task gates the next step.

Adds a new top-level section End the turn only when work is shipped to running-in-ci, placed after Restrictions. Rule: treat the session as live until the deliverable is maintainer-visible (pushed, posted, opened); don't background work whose output gates the deliverable; the run_in_background recipe under CI Monitoring stays safe because it runs after push.

Evidence

  • tend-mention run 27051779110 — backgrounded pre-merge gating a deprecation PR, session ended mid-wait, no PR shipped.
  • tend-notifications run 27053336290 — picked up the deferred work, implemented cleanly on local branch deprecate/squash-commits-var-27053336290, ~17 min and $7.35 of session, never called Monitor, branch never pushed, no comment.
  • tend-mention run 27075856123 — different PR (worktrunk#2991), full rework implemented, called Monitor({}) with empty input → InputValidationError, loaded the schema via ToolSearch but never retried, end_turn with text "I'll be re-invoked when it finishes". It was not.

Classification. Three occurrences inside ~17 hours, across two worktrunk PRs and two workflow types (tend-mention twice, tend-notifications once). Gate 1 (High structural needs 2–3 occurrences). Gate 2 (targeted fix at Normal threshold).

Evidence gist: https://gist.github.com/15c523384cfad7449cb81933b47165ff

Backgrounding a multi-minute local validation (`cargo run -- hook
pre-merge --yes`, full test suite, comprehensive lint) behind a
`Monitor` wait before `git push` / `gh pr create` destroys the
deliverable when the session ends mid-wait. Two consecutive worktrunk
sessions in the same two-hour window did real code work for the same
maintainer ask, then silently failed to ship because both gated the
push on a backgrounded pre-merge run that outlived the session budget.

Add a subsection to PR Creation telling the bot to sequence the
visible deliverable (commit, push, `gh pr create`) first and let CI
re-run the matrix after push. A targeted compile plus the tests
exercising the change is enough local confidence to ship.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@tend-agent tend-agent added the claude-behavior Behavioral issues found by review-reviewers label Jun 6, 2026
@max-sixty

Copy link
Copy Markdown
Owner

But why did the session end? That seems like the core problem here!

Is this a problem with running without -p?

Is max-sixty/worktrunk#2986 similar? Is that running without -p?

@tend-agent

Copy link
Copy Markdown
Collaborator Author

You're right that this PR papers over the symptom. The root cause:

Why the session ends. Both failed runs emitted stop_reason: end_turn with the background cargo run -- hook pre-merge --yes task still pending. The model treats run_in_background: true + Monitor as "yield and get woken on completion." That wakeup model only works reliably in interactive Claude Code (a human terminal session, where the binary stays alive after end_turn waiting for the next user message). In CI the session terminates and the runner is discarded before the background task can notify.

Is this a -p problem? Structurally yes. worktrunk uses the default harness: claude, which runs anthropics/claude-code-action — the Agent SDK, one-shot, equivalent to claude -p. Tend itself runs harness: claude-interactive (the PTY-supervised binary), but that harness also exits on end_turn via a Stop-hook sentinel (interactive/action.yaml:5-7) — same constraint in CI for a different reason. Neither CI harness can hold the session open through a multi-minute background wait. There is one subtle wrinkle: action.yaml already documents task-notification wakeups that emit a second result (action.yaml:321-324), so claude-code-action does have some wakeup support — but in worktrunk's runs the wakeup never fired before the session terminated, suggesting either the wakeup window is shorter than the gate's runtime or the model emitted a "final" end_turn the SDK didn't queue a wakeup for. I haven't traced exactly which.

Is worktrunk#2986 the same? Yes — same end_turn-with-pending-background root cause, same pre-merge gate, same two runs cited. The difference is scope: worktrunk#2986 adds a narrow rule to worktrunk's running-tend overlay (specifically: foreground the pre-merge hook), this PR adds a broader rule to the bundled running-in-ci skill (any long pre-push wait). They don't conflict, but they're redundant if both land.

Given the questions, two options I'd take direction on:

  1. Close this, keep worktrunk#2986. The bundled rule is overreach if the only consumer hitting it has a project-specific gate; worktrunk-specific guidance is the right level.
  2. Reframe this so it states the harness constraint up-front ("Agent-SDK / claude -p mode terminates on end_turn; CI never resumes from a background-task wakeup the way interactive Claude does") rather than just the rule, so future readers understand why and can decide differently if the harness ever changes.

The deeper structural fix — having claude-code-action block end_turn while a run_in_background Bash is still running — would belong upstream in claude-code-action and is out of scope here.

@tend-agent

Copy link
Copy Markdown
Collaborator Author

3rd occurrence of the same shape this hour, on a different PR.

tend-mention run 27075856123 — handle ran 22:39:11Z → 22:51:40Z (12m29s), triggered by max-sixty's "great, yes, let's do that" on PR #2991 (agreeing to centralise control-byte escaping in src/logging.rs rather than the narrow per-call site the earlier commits used). The session implemented the full rework — added escape_controls helper to src/utils.rs, reverted producer-side escaping in src/shell_exec.rs, applied centralised escaping in src/logging.rs + src/diagnostic.rs, added an integration test test_vv_artifacts_have_no_raw_control_bytes — ran targeted tests locally (all passed), then queued cargo run -- hook pre-merge --yes as run_in_background and Monitor-waited. Final assistant text: "Waiting on the full suite before committing and pushing." Session emitted end_turn; never resumed. Zero output on PR #2991: branch never pushed, no commit, no comment. Same stop_reason: end_turn + pending background pre-merge as the two runs in the PR body.

Cadence. 3 occurrences inside ~17 hours, across 2 worktrunk PRs (#2983 twice, #2991 now) and 2 workflow types (tend-mention twice, tend-notifications once). All inside max-sixty/worktrunk — consistent with worktrunk#2986's overlay-level scope. The bundled-vs-overlay choice from my prior comment still stands; this just sharpens the rate.

Maintainer-impact signal. Each occurrence leaves a visibly unanswered maintainer ask. PR #2991 now sits with max-sixty's "great, yes, let's do that" unresponded-to, even though the bot did the rework — the maintainer can't see that and has no reason to expect a sibling cycle will redo it. The invisibility is the user-facing harm worth pricing in.

No response needed — posting as evidence for the open decision. Recorded in the evidence gist.

@max-sixty

Copy link
Copy Markdown
Owner

There is one subtle wrinkle: action.yaml already documents task-notification wakeups that emit a second result (action.yaml:321-324), so claude-code-action does have some wakeup support — but in worktrunk's runs the wakeup never fired before the session terminated, suggesting either the wakeup window is shorter than the gate's runtime or the model emitted a "final" end_turn the SDK didn't queue a wakeup for. I haven't traced exactly which.

please explain?

@max-sixty

Copy link
Copy Markdown
Owner

consider generalizing this to a simple "do not end the turn until everything is complete"?

Replaces the narrow "Ship the deliverable before any long wait" subsection
under PR Creation with a top-level "End the turn only when work is shipped"
section. The failure mode generalises beyond PR creation — any case where
`end_turn` fires while a maintainer-visible deliverable is staged but
un-shipped has the same shape (comment posting, follow-up commits, inline
replies). Reframes after maintainer review #661.

The wakeup-mechanism evidence from the cited runs shows the model never
attaches a `task-notification` subscription before `end_turn` (either no
`Monitor` call, or `Monitor({})` failing with InputValidationError because
the deferred-tool schema isn't loaded), so even if the underlying wakeup
window is generous the model can't reach it. Rule sidesteps this: don't
end the turn while the deliverable is un-shipped, regardless of why.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@tend-agent tend-agent changed the title skills(running-in-ci): ship the deliverable before any long wait skills(running-in-ci): end the turn only when work is shipped Jun 7, 2026
@tend-agent

Copy link
Copy Markdown
Collaborator Author

Traced both session logs — the wakeup never fired because neither failed run successfully subscribed to one. Resolves my earlier "haven't traced exactly which" hedge:

Run 27053336290. Backgrounded cargo run -- hook pre-merge --yes at 05:20:00Z — the SDK created a tracked task (output at …/<session-id>/tasks/b4uib1zkg.output). The model then polled with sleep 90; tail, wrote /tmp/pr-body.md, re-read the task output, looked up Monitor via ToolSearch:select:Monitor — and emitted end_turn without ever calling Monitor. No active wait, no wakeup slot.

Run 27075856123. Same shape, but the model did call Monitor — at 22:51:05.138 it issued Monitor({}) with empty input, and got back InputValidationError: required parameter 'description' is missing (Monitor is a deferred tool — its schema must be loaded via ToolSearch:select:Monitor before the call, not after). At 22:51:08 it loaded the schema, but never retried Monitor — straight to end_turn at 22:51:23 with text claiming "the full test suite is running as a tracked background task and I'll be re-invoked when it finishes". It was not.

So: neither "wakeup window too short" nor "final end_turn the SDK didn't queue a wakeup for". It's the model never attached the subscription in the first place. claude-code-action's task-notification wakeup (action.yaml:321-324) appears to be tied to a successful Monitor call subscribing to the task — end_turn without an active wait reads to the SDK as a clean exit regardless of pending background Bash. (One unverified detail: I can't tell from the logs whether the SDK would also drop the wakeup after some bounded window if a wait were active. That's the layer below where this rule needs to bite.)

Re: generalising to "do not end the turn until everything is complete" — yes, that's the right framing. Even when Monitor is invoked correctly the attach is fragile (deferred-tool schema dance + correct args + reliable wakeup window). The robust rule cuts through all of that: don't end_turn while the deliverable is staged but un-shipped, regardless of why it's un-shipped. I'll rewrite the section to a top-level End the turn only when work is shipped that applies to PR creation, comment posting, follow-up commits — anywhere the maintainer-visible artefact is gated on something the model is waiting on. The existing run_in_background: true recipe under CI Monitoring stays intact (it runs after push, so the deliverable is already shipped — worst case is a missed CI-result follow-up, not a lost PR).

Pushing the rewrite in a follow-up commit on this branch.

@max-sixty
max-sixty merged commit 4fe441e into main Jun 7, 2026
5 checks passed
@max-sixty
max-sixty deleted the skills/ship-before-waiting-27054491689 branch June 7, 2026 08:48
tend-agent added a commit that referenced this pull request Jun 8, 2026
…re end_turn"

Triage Step 6.3's "Run the full test suite and lints" conflicts with
running-in-ci's "End the turn only when work is shipped" (#661): a long
suite kicked off before push pushes the agent into mid-wait end_turn
and the deliverable never ships. Fold the targeted-test check into
Step 2 and renumber.

Closes a 2-occurrence pattern (May tend-mention #5741, June tend-triage
on PRQL/prql#5988) where the agent finished real work, called
ScheduleWakeup expecting resumption, and exited without commit/push.

Co-Authored-By: Claude <[email protected]>
@max-sixty max-sixty mentioned this pull request Jun 11, 2026
max-sixty added a commit that referenced this pull request Jun 11, 2026
Bumps the generator version to 0.1.4, syncs the lockfile, and adds the
0.1.4 CHANGELOG section (published as the GitHub Release notes on tag
push).

Notable changes since 0.1.3:

- Claude harnesses switch to `bypassPermissions` (#677)
- GitHub Releases publish from `CHANGELOG.md` on tag push (#678) — this
release is the first live exercise of that workflow
- Interactive sandbox receives GitHub Actions context env vars (#664)
- install-tend bot-token step restructured around scope-audit
remediation (#680)
- Review skill checks the rollup before APPROVE (#667);
running-in-ci/triage/ci-fix skill refinements (#661, #666, #669, #670,
#671)

> _This was written by Claude Code on behalf of max_

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude-behavior Behavioral issues found by review-reviewers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants