Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions docs/architecture/on-demand-agent-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,24 @@ Under orchestrator ownership the worktree becomes a hot path.
record says the snapshot was *not* pushed and asks for escalation
rather than reassuring the successor that nothing was lost. The ask
also scales with *what* the snapshot captured: when every captured path
is an **orchestrator-written** state file, the record softens to "read
it if you need it" so a routine respawn does not train the #3509
message into background noise. The allowlist is
`.egg-state/agent-outputs/*/brc-memory*.md` (rewritten on every
`brc_ack`/`brc_nack`), `.egg-state/agent-outputs/consensus-confirmed`,
and `.egg-state/agent-outputs/<pipeline-id>-apply-handoff.json`;
matching is segment-wise so `*` does not cross `/`. Files written by
*agents* into the same directory — `<pipeline>-wontdo.json`,
`<identifier>-tester-output.json` — are deliberately excluded: they are
agent output, and losing them warrants the imperative. Anything else —
is a **state file the next event regenerates and some other store
durably holds**, the record softens to "read it if you need it" so a
routine respawn does not train the #3509 message into background noise.
The membership test is regeneration, not authorship — the dominant
member is written by the *sandbox* on the agent's own tool call and
holds agent-authored prose. The allowlist is
`.egg-state/agent-outputs/*/brc-memory*.md` (rewritten by
`sandbox/egg_agent_tools/handlers/brc_memory.py` on every
`brc_ack`/`brc_nack`, with the orchestrator message history as the
durable backstop — see
[brc-memory.md](brc-memory.md)),
`.egg-state/agent-outputs/consensus-confirmed`, and
`.egg-state/agent-outputs/<pipeline-id>-apply-handoff.json`;
matching is segment-wise so `*` does not cross `/`. Agent *output* in
the same directory — `<pipeline>-wontdo.json`,
`<identifier>-tester-output.json` — is deliberately excluded: nothing
rewrites it on the next event and no other store holds it, so losing it
warrants the imperative. Anything else —
including an unrecognised or unknown file set — keeps the imperative
"inspect it before starting work", as does a snapshot flagged partial
(a truncated capture's path list omits whatever failed to stage, so it
Expand All @@ -223,7 +231,14 @@ Under orchestrator ownership the worktree becomes a hot path.
reconstruct the decision instead of regexing the prose; the two derived
fields diverge whenever a machine-state-only path set is disqualified
by a commit stack, a truncated capture, or a failed salvage push. The
threshold selects wording only; the snapshot itself is always taken. A
threshold selects wording only; the snapshot itself is always taken —
including when the path list cannot be read at all. The staged-path
read uses `-z` so `wip_paths` carries real bytes rather than
`core.quotePath` C-quoted tokens, which means a filename that is not
valid UTF-8 makes the read undecodable under `subprocess`'s strict
`text=True` decode; that logs a WARNING and commits blind
(`wip_paths`/`wip_files` become `null`, so the record takes the
imperative) rather than letting a filename cost the working tree. A
snapshot whose `git add -A` reported errors is marked incomplete in
both its commit message and the bus record, since a truncated snapshot
is otherwise indistinguishable downstream from a complete one. The same
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/agent-recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ git switch <target-branch>
git cherry-pick <recovered-base>..recovered/<scope>
```

**Review before replaying: a recovery ref may hold un-reviewed working-tree residue.** Both working-tree snapshot paths ([#2807](https://github.com/jwbron/egg/issues/2807) restart, [#3639](https://github.com/jwbron/egg/issues/3639) re-attach) stage with `git add -A`, so a snapshot commit contains everything the agent left in the worktree that is not `.gitignore`d — scratch dumps, logs, stray state files — with no agent or human intent behind any of it. Recovery refs are a preservation mechanism, not an endorsement: read the diff before cherry-picking, and expect a snapshot-only ref to sometimes hold nothing you want. Reading the diff before replaying is the control here: **nothing in this repo enables GitHub push protection**, so do not assume a snapshot containing a secret is stopped on the way out. (Where push protection *is* enabled on the receiving repo it rejects such a push rather than leaking it, and the discard is then recorded with `salvage_error` set instead of a recovery ref — the failure branch described above.)
**Review before replaying: a recovery ref may hold un-reviewed working-tree residue.** Both working-tree snapshot paths ([#2807](https://github.com/jwbron/egg/issues/2807) restart, [#3639](https://github.com/jwbron/egg/issues/3639) re-attach) stage with `git add -A`, so a snapshot commit contains everything the agent left in the worktree that is not `.gitignore`d — scratch dumps, logs, stray state files — with no agent or human intent behind any of it. Recovery refs are a preservation mechanism, not an endorsement: read the diff before cherry-picking, and expect a snapshot-only ref to sometimes hold nothing you want. **A snapshot may also be incomplete**: when `git add -A` reported errors the commit holds only what reached the index, and its message carries an `INCOMPLETE: \`git add -A\` reported errors while staging` paragraph saying so — `git log -1 <ref>` before you conclude the ref holds everything the working tree did. On the [#3639](https://github.com/jwbron/egg/issues/3639) re-attach path a bus record repeats that warning, but on the [#2807](https://github.com/jwbron/egg/issues/2807) crash-salvage path (`commit_working_tree`) there is no bus record at all, so the commit message is the only channel a triager gets. `git log --all --grep 'INCOMPLETE: `git add -A`'` finds every truncated snapshot from either path. Reading the diff before replaying is the control here: **nothing in this repo enables GitHub push protection**, so do not assume a snapshot containing a secret is stopped on the way out. (Where push protection *is* enabled on the receiving repo it rejects such a push rather than leaking it, and the discard is then recorded with `salvage_error` set instead of a recovery ref — the failure branch described above.)

Operators may delete `egg/recovered/*` refs manually after replay (`git push origin --delete <ref>`). For automatic cleanup of refs left behind by replays that never came, see [Recovery Ref Cleanup](#recovery-ref-cleanup) below.

Expand Down
13 changes: 12 additions & 1 deletion orchestrator/agent_salvage.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,18 @@ def commit_working_tree(worktree: AgentWorktree) -> str | None:
return None
head = _run_git("rev-parse", "HEAD", cwd=worktree.repo_path, check=False)
head_sha = (head.stdout or "").strip() if head.returncode == 0 else None
except (OSError, subprocess.SubprocessError) as e:
# Deliberately broader than the ``(OSError, subprocess.SubprocessError)``
# the read helpers above use, and broader than it needs to be today. The
# docstring promises this never raises, and the class that would break
# that promise is not a subprocess error: ``_run_git`` decodes with
# ``text=True`` and no ``errors=``, so a git command that echoes a
# filename whose bytes are not valid UTF-8 raises ``UnicodeDecodeError``
# (a ``ValueError``) from inside ``subprocess.run``. Unreachable on this
# path today — it has no ``-z`` call and the default ``core.quotePath``
# keeps git's output ASCII — but the re-attach path shipped exactly that
# bug by adding ``-z`` (#3639 re-review B1), and letting it escape here
# would abort the committed-but-unpushed salvage that follows.
except Exception as e:
logger.warning(
"Salvage: capturing uncommitted working tree raised; continuing",
worktree_id=worktree.worktree_id,
Expand Down
Loading
Loading