Skip to content

work-loop: escalation record write is blocked when the lane runs as a background job #4598

Closed

Description

@kyle-sexton

This was generated by AI during work-loop.

Observed

A /work-items:work-loop lane launched as a Claude Code background job (session claude.ai/code/session_01YXxu4tpPEWHkH44Y2JdS1i, instance melo-lap-001-wsl-1, 2026-09-27) could not write any escalation record. The step-5 Write-tool write to .claude/lane-escalations/<stamp>-<item>-work-loop.json was refused with: "parent bg session hasn't isolated yet, so writes to the shared checkout are blocked". Five kind=ratify-c3 / kind=escalated markers were posted (#3351, #3526, #3589, #3612, #3614) with no record written.

Why it matters

The background-job harness blocks file edits in the shared checkout until the session calls EnterWorktree. The work-loop skill forbids exactly that: the lane runs on the default-branch checkout, and EnterWorktree would transition the orchestrator session. Step 0 of the cycle makes the directory git-ignored, but the harness block applies anyway. So every escalation's out-of-band notification leg is lost whenever the lane runs as a background job. The tracker comment stays the escalation of record.

Possible directions

  • Write the record under a path outside the checkout (for example under $CLAUDE_JOB_DIR or a user-scope lane directory) that a notification hook can still key on.
  • Document that background-job launches lose the record leg, and name the launch mode that keeps it.

Evidence

  • plugins/work-items/skills/work-loop/SKILL.md "Cycle shape" step 5 (record path relative to the checkout, Write tool required).

Activity

  1. added
    needs-triageNot yet classified. Floor until a type and one priority tier are set.
    needs-humanHuman-in-the-loop required; autonomous sessions must not resolve items carrying this.
    and removed
    needs-triageNot yet classified. Floor until a type and one priority tier are set.
    on Sep 27, 2026
  2. added theissue type on Sep 27, 2026
  3. kyle-sexton commented on Sep 27, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Triage: Bug, priority: medium, human-gated (open contract decision).

    Verified (at the contract level). The work-loop "Cycle shape" step 5 writes the escalation record with the Write tool to a path relative to the session's checkout (.claude/lane-escalations/…), and step 0 only git-ignores that directory. Ignoring the path does not lift a harness write block on the shared checkout, so the reported refusal fits the text. I did not reproduce the background-job refusal itself here.

    Scope is wider than work-loop. The record path and the Write-tool rule are part of the loop-lane convention (escalation record section and its example notification hook, which matches Edit(/.claude/lane-escalations/**)). The babysit-loop cycle shape and the escalation-marker reference restate the same contract. Any fix applies to every lane that writes the record.

    Why a human decides. Both directions in the report change a published contract:

    1. Move the record out of the checkout (for example the job directory or a user-scope lane directory). Keeps the notification leg under background jobs, but every consumer's hook matcher keyed on the project-relative path stops firing until it is updated. That is a schema/contract change across lanes and consuming repos.
    2. Document the limitation. State that background-job launches lose the record leg, name the launch mode that keeps it, and leave the tracker comment as the escalation of record. No consumer breakage, but the out-of-band signal stays unavailable in that mode.

    Recommendation: option 1 with a versioned record location (keep the checkout path when writable, else fall back to a user-scope directory), plus a matching update to the convention's example hook. That is judgment, not measured. Picking the option unblocks a scoped implementation brief.

    Reporter severity was not stated. priority: medium because the tracker comment remains the escalation of record, so no escalation is lost; only the notification is.

  4. kyle-sexton commented on Sep 27, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during work-loop.

    Data point from a second lane: instance melo-lap-001-wsl-2, also a background job, launched in the lane worktree /home/kyle/worktrees/cc-plugins-lane-2 (not under .claude/worktrees/). There, three Write-tool calls to .claude/lane-escalations/<stamp>-<item>-work-loop.json succeeded on 2026-09-27 at about 18:32Z, for #4351, #4345, and #4346. So the block does not happen in every background-job lane. It may depend on whether the session's working directory counts as the shared checkout or as an already-isolated worktree. Please check that before choosing between moving the record path and documenting the lost record leg.

  5. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    Reopened. This comes from the 2026-09-29 audit of the Cursor run, and the audit chooses no option.

    What the audit found

    1. docs(work-items): document background-job escalation record limit (#4598) #4912 documented the limitation (option 2), although triage recommended option 1 (versioned fallback record location) and the lane-2 comment asked for a check before choosing. No comment on this issue records a decision or the check.
    2. The only counter-evidence: melo-lap-001-wsl-2, also a background job but running in the isolated lane worktree cc-plugins-lane-2, completed three Writes to .claude/lane-escalations/ (Three skill descriptions exceed the 1024-codepoint limit and fail check-skill #4351, docs(babysit-prs): stuck-checks reference routes label fixes to the deleted select-runner workflow #4345, playbooks: regenerate the fable-5 doctrine for Fable 5.1 #4346). The trigger looks like "session not yet isolated", not "background job".
    3. Triage did not reproduce the refusal.

    Fix PR #5325 (Refs #4598) is docs accuracy only: it words the limitation as "observed, conditional on isolation". It does not decide the question.

    Decision needed (owner)

    Question: how should loop lanes keep the out-of-band escalation record when Claude Code runs them as background jobs?

    Options:

    • A. Move the record to a versioned fallback location outside the shared checkout (triage's recommendation; needs a scoped brief naming the location and the hook consumer).
    • B. Keep the documented limitation (what main has now, corrected by fix(work-items): resolve audit findings for work-loop, adapter release verb, and skill docs #5325 to "observed, conditional on isolation").
    • C. Document and recommend launching the background job from an isolated lane worktree once the check confirms it (cheapest, changes no code).

    B and C can combine.

    RECOMMENDED (a recommendation, not a decision): run the check first. If a background job from an isolated worktree reliably keeps the Write, choose C with B as the fallback statement; pick A only if operators cannot launch from lane worktrees. Basis: this issue's second comment (three successful Writes), triage's non-reproduction, judgment on cost. No official Claude Code doc read supports either claim yet.

    Operator steps for the check (needs a live session): from the default-branch checkout, start the work-loop as a background job with one item that forces an escalation, then repeat from an isolated lane worktree. In each run, look for a file under .claude/lane-escalations/ and for the harness error text.

    Unblocks: a scoped implementation brief for the chosen option. needs-human and work-class: structural stay on the issue.

  6. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    Correction to the decision packet above: it says no official Claude Code doc read supports either claim yet. That is wrong. The work-loop SKILL.md verification record on PR #5325 cites https://code.claude.com/docs/en/agent-view#how-file-edits-are-isolated, which says writes to the shared checkout are blocked until the session moves into a worktree and that the move is skipped when the session is already inside a linked git worktree. That agrees with the conditional-on-isolation reading; the refusal itself is still not reproduced.

  7. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    Update from the 2026-09-29 audit remediation: the babysit-loop skill restated the escalation-record write (plugins/source-control/skills/babysit-loop/SKILL.md, escalation section) without the background-job caveat. PR #5317 (merged) adds a pointer there to the loop-lane convention's "Background-job launch mode" paragraph, so the third restatement now points at the same interim wording as work-loop (PR #5325) and docs/conventions/loop-lane/README.md. No option is chosen; the decision stays open here.

    #5317

  8. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    Owner decision (2026-09-29): Option C with B as the fallback statement, after a live check. Owner's words: "Accept recommendation: C with B as fallback statement, after a live check". That means: document and recommend launching background jobs from an isolated lane worktree, and keep the documented limitation (as worded in #5325) for sessions that are not isolated. Option A (moving the record location) is not chosen.

    Next: the live check stays with the owner: run the work-loop as a background job that forces an escalation, once from the default-branch checkout and once from an isolated lane worktree, and record whether a file appears under .claude/lane-escalations/ plus any harness error text. needs-human stays until the result is posted here. If the isolated launch keeps the Write, the C doc edits follow (doc-only, no code). If it does not, this comes back to the owner for a re-decision.

  9. kyle-sexton commented on Sep 30, 2026

    @kyle-sexton
    MemberAuthor

    Resolution (2026-09-29, owner-approved consensus)

    Goal. Find out whether a work-loop lane launched as a Claude Code background job can write .claude/lane-escalations/<stamp>-<item>-work-loop.json, and if it can, update the docs to name the launch mode that keeps the record leg. This is the live check the owner asked for on 2026-09-29 (option C, with B as the fallback wording).

    Steps.

    1. Probe from a scratch worktree under .work/, not the live checkout. Use a minimal prompt that exercises the same Write path as work-loop step 5: "Use the Write tool to create .claude/lane-escalations/probe-.json containing {}; then report the exact tool result or error text."
      • Run 1: claude --bg --name probe-default "<prompt>" from a plain default-branch checkout that is not a linked worktree.
      • Run 2: create an isolated lane worktree outside .claude/worktrees (as cc-plugins-lane-2 was) and run the same claude --bg from inside it.
      • Read the results with claude agents or the job transcript. Record whether the file exists, where it landed (checkout or worktree path), and the harness error text if refused.
    2. Post the results on this issue. Per https://code.claude.com/docs/en/agent-view#how-file-edits-are-isolated, a background session moves into an isolated worktree before its first edit and skips the move when already in a linked worktree. So Run 1 may succeed but write into the auto-created worktree, which matters for hook matchers on the project-relative path. Run 2 should write in place.
    3. If Run 2 keeps the Write, make a doc-only follow-up: edit docs/conventions/loop-lane/README.md ("Background-job launch mode"), plugins/work-items/skills/work-loop/SKILL.md and the babysit-loop SKILL.md to recommend launching from an isolated lane worktree, and keep the B wording for non-isolated sessions. Add the verification record and ## Next section the skill-bodies rule requires. Open a draft PR with Closes #4598.
    4. If Run 2 fails, return the issue to the owner for re-decision (option A).

    Acceptance criteria.

    • Both probe runs are recorded on this issue with file existence, path, and exact error text.
    • The docs state which launch mode keeps the escalation record, matching the probe results.
    • The doc edits carry the verification record and ## Next section, and the PR uses the Conventional Commits title and the PR body contract.
    • No change to work-loop behavior beyond docs, and no EnterWorktree in the orchestrator.

    Notes. Prerequisites checked on origin/main: #5325 is merged and the convention already has the interim B wording. The probes are local and non-destructive but spend plan usage; if probing from an agent is unwanted, the owner can run them by hand.

  10. added
    agent-readyFully specified and briefed; eligible for autonomous pickup from the frontier.
    and removed
    needs-humanHuman-in-the-loop required; autonomous sessions must not resolve items carrying this.
    on Sep 30, 2026
  11. kyle-sexton commented on Sep 30, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during work-loop.

    Live check for the Resolution comment, run 2026-09-29 with Claude Code 2.1.285 (claude --bg, auto mode). Reference: https://code.claude.com/docs/en/agent-view#how-file-edits-are-isolated

    Prompt in both runs: "Use the Write tool to create .claude/lane-escalations/probe-.json containing {}; then report the exact tool result or error text."

    Run 1 (plain, non-linked default-branch clone): not run. I made a plain git clone --local -b main of the repo under .work/probe-4598/default. claude --bg --name probe-4598-default ... refused to start there:

    Workspace not trusted. Run `claude` in <clone path>/.work/probe-4598/default once and accept the trust prompt, then retry.
    

    Trust is recorded per path in ~/.claude.json, and only the live checkout is trusted. Accepting the prompt is a user-scope config write, so I did not do it, and running the probe in the live checkout is excluded. No file, path or harness error text exists for this run. The owner needs to accept the trust prompt for a plain clone (or run the probe by hand) to complete it.

    Run 2 (linked lane worktree outside .claude/worktrees): the Write was kept, in place. The worktree was git worktree add --detach .work/probe-4598/lane origin/main from the live repo (a linked worktree of the trusted repo, so the trust prompt did not apply). claude --bg --name probe-4598-lane ... was started from inside it.

    • Tool result: Wrote 1 line to .claude/lane-escalations/probe-lane-1.json (permission line: "Allowed by auto mode classifier"). No refusal and no "hasn't isolated yet" text.
    • File exists: yes, {} (2 bytes).
    • Absolute path where it landed: /home/kyle/repos/github.com/melodic-software/claude-code-plugins/.work/probe-4598/lane/.claude/lane-escalations/probe-lane-1.json, the lane worktree itself. No auto-created worktree appeared, and no copy was found elsewhere under /home/kyle.
    • Job state (claude agents --json): probe-4598-lane, state: done.

    So the isolated-lane launch keeps the record leg, matching the docs and the cc-plugins-lane-2 data point. The refusal in the original report is still not reproduced. Run 1 is what would show it, and it is still open.

    Cleanup: the probe clone, the lane worktree and both probe background sessions are removed after this comment.

  12. kyle-sexton commented on Oct 1, 2026

    @kyle-sexton
    MemberAuthor

    Owner decision (2026-10-01): approved the recommendation ("go with recommended", the owner's reply to the batch decision page that listed this question and its recommendation).

    Question: close #4598 as done on probe Run 2 plus the docs merged in #5549 and drop probe Run 1, or keep it open until Run 1 is run?

    Chosen option A: close as completed and drop Run 1. Run 2 (isolated linked worktree) kept the Write in place, which was the condition for the doc edits, and #5549 shipped them. The docs already hedge the non-linked launch ("may have the Write refused or landed in an auto-created worktree"), so Run 1 cannot change the advice. The owner waives the Run 1 acceptance criterion.

    Next: closing this issue as completed. If a lane later hits a refusal, reopen or file a new issue.

  13. removed
    agent-readyFully specified and briefed; eligible for autonomous pickup from the frontier.
    on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions