Skip to content

Count Untracked Files in the Dirty Stamp, State the Session Tree Bound - #4311

Merged
ptr727 merged 3 commits into
developfrom
burndown/safety-kit-stamp-req9
Nov 20, 2026
Merged

ptr727 merged 3 commits into
developfrom
burndown/safety-kit-stamp-req9

Conversation

@ptr727

@ptr727 ptr727 commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Two agent-safety kit changes, each approved on its issue. The merge waits on the maintainer's read of this diff.

  • Dirty stamp counts an untracked payload file. The git status --porcelain read behind the stamp's dirty field in host-setup/agent-safety/claude/install.py passes --untracked-files=all. It is the same flag scripts/skills_install.py passes on both of its cleanliness reads. Before this change, a host with status.showUntrackedFiles=no stamped dirty=False over a payload file no commit holds, so --report never printed "installed from a dirty checkout". A new test, TestSourceRefUntrackedPayload, builds a throwaway git tree under a temp directory. It commits every payload file but one, sets status.showUntrackedFiles=no in that tree's own config, and adds the last payload file untracked. It then reads the real status, with AGENT_SAFETY_DIRTY_OVERRIDE unset. It asserts that a plain git status --porcelain prints nothing there, and that source_ref() reports dirty as true. The test fails against the old read and passes against the new one. It shares a fixture, KitTreeCase, with the existing archive cases. That fixture clears git's location variables through spec/git_env.py, so a git hook running the suite cannot point a case's git commands at another repository. It also points global and system git config at an empty file, so a host's hooks path, template, or fsmonitor never reaches a temp-tree commit. It holds the one identity-pinned git helper all three git-building cases use. That closes the same gaps in two existing archive cases that run git init and git commit. Everything a case writes stays inside its temp directory, which it removes.
  • Dirty read passes kit-relative pathspecs. The same read passes each payload path relative to the kit directory, where it runs git -C, rather than as an absolute path. scripts/skills_install.py passes repo-relative paths for the same reason: under git -C, an absolute pathspec can match nothing and read clean. TestSourceRef still detects a dirtied payload file in a real checkout, and reads a clean one as clean.
  • Requirement 9 states the session tree. host-setup/agent-safety/README.md requirement 9 now states two things the Claude kit already does. First, a nested agent session's commands run in groups of their own, and every group in a chain of nested sessions sits under one total ceiling for the whole tree. Where the tree's ceiling cannot be put on, a command still runs under its own ceilings and says the tree has none. Second, the session-end stop also stops a group named for another session, but only where that group is in this session's tree and the agent it records has ended. That stop is bounded by the tree and the recorded agent, and judges nothing about the group's own processes. The Codex and opencode tree bound stays with Add safety hooks for opencode and codex #781, which stays deferred. Requirement 9 is agent-agnostic, so an implementation of it there includes the tree bound.

host-setup/agent-safety/claude/README.md already describes the tree slice and the orphan stop, and says nothing about the dirty read's untracked mode, so it is unchanged.

Closes on promotion: #4147, #2598

For the Maintainer to Run: Does a Nested Session Inherit CLAUDE_CODE_SESSION_ID?

#2598's approved option asks for a nested claude -p run to check whether a nested session inherits the parent's CLAUDE_CODE_SESSION_ID. A nested agent session is a live run outside a worker's own workspace, so this pull request did not run it. The requirement 9 text above states what the kit must do and holds either way. If the session id is inherited, the Claude kit is what falls short of the requirement, and that is a kit defect to file.

Run this as one Bash tool call inside a Claude Code session on a Linux host where the kit's containment prefix is registered. Run it in a session with nothing else in flight. In the inherited case, the nested session's sweep stops the parent session's own command scopes, this command's scope included.

d=$(mktemp -d) && printf '#!/bin/sh\n{ echo "env=$CLAUDE_CODE_SESSION_ID"; echo "root=$AGENT_CONTAINMENT_ROOT"; cat; echo; } > "%s/sessionend.txt"\n' "$d" > "$d/hook.sh" && chmod +x "$d/hook.sh" && printf '{"hooks":{"SessionEnd":[{"hooks":[{"type":"command","command":"%s/hook.sh"}]}]}}\n' "$d" > "$d/settings.json" && echo "dir=$d parent=$CLAUDE_CODE_SESSION_ID" && timeout 300 claude -p --settings "$d/settings.json" --allowedTools Bash 'Run this Bash command and print its output verbatim: echo "tool=$CLAUDE_CODE_SESSION_ID root=$AGENT_CONTAINMENT_ROOT"; cat /proc/self/cgroup' ; cat "$d/sessionend.txt"

Expected observations, own id (requirement 9 holds as implemented):

  • tool= and the hook's env= print the same id, and it differs from parent=.
  • The hook's stdin payload carries that same id as session_id.
  • root= prints the parent's id, where the parent is itself a root session.
  • The cgroup line names a claude-tool-<nested id>-... scope inside claude-tree-<parent id>.slice.
  • The outer command runs to its last cat.

Expected observations, inherited id (a kit defect against requirement 9):

  • tool= or env= prints the parent= id. Note whether the payload's session_id is the parent's id too, since the sweep reads both.
  • The cgroup line names a claude-tool-<parent id>-... scope, so the nested session's commands are grouped under the parent's name.
  • The nested SessionEnd sweep's first phase stops the parent's scopes. So the outer command can be cut off before its last cat. Read sessionend.txt under the printed dir= from a fresh tool call.

Local Review Findings Still Open

Three local passes ran. The two rounds of edits fixed every introduced finding from the first two passes. The third pass raised the findings below after that budget was spent. Each one's class and the outcome this pull request's review loop gave it follow.

  • host-setup/agent-safety/claude/install.py source_ref(), the dirty read (introduced, design): it repeats the --untracked-files=all and relative-pathspec shape of scripts/skills_install.py source_ref() rather than sharing one primitive. Outcome: declined. A shared helper across the two installers is a refactor of scripts/skills_install.py, which is outside this change's approved design and its file claim. This diff brings the two copies into agreement rather than further apart.
  • host-setup/agent-safety/claude/install.py source_ref(), ref["dirty"] = bool(status) (introduced by proximity, correctness): a git status that exits non-zero reads as clean. Outcome: declined under GOVERNANCE.md "Trust Boundaries and Hardening Effort". The read runs in the maintainer's own checkout, right after rev-parse HEAD succeeds there. A status failure then needs a corrupt or unreadable index, and this change removed the outside-the-repository pathspec route to one.
  • host-setup/agent-safety/README.md requirement 9, "where stopping its parent's group ended the nested agent before its own stop ran" (style): a past-tense remark. Outcome: declined. The tense orders two events inside one case rather than describing a change from a prior state, which is what the present-tense rule governs.

Dropped Findings

  • host-setup/agent-safety/claude/test_install.py TestSelftestIgnoresAmbientGitDir: consolidation onto spec/git_env.py, on text this change did not touch.

Pre-Existing Findings, Not Filed

  • host-setup/agent-safety/claude/tool-containment.py decide(): where neither AGENT_CONTAINMENT_ROOT nor CLAUDE_CODE_SESSION_ID yields a token, a command runs with no tree ceiling and no notice (correctness, declined). Claude Code sets CLAUDE_CODE_SESSION_ID in a tool call's environment, so the deployment does not produce that case.

Verification

  • python3 -m unittest test_install in host-setup/agent-safety/claude/: 238 tests, OK.
  • TestSourceRefUntrackedPayload run against the old install.py: 1 failure, the assertion that dirty is true.
  • ruff format and ruff check over host-setup/agent-safety/claude/, mypy over the repository, and the prose gate against develop are clean. The pre-commit hook ran each on the commit.

🤖 Generated with Claude Code

ptr727 and others added 3 commits November 19, 2026 18:09
The agent-safety installer's dirty-stamp status read passes
--untracked-files=all, so a host with status.showUntrackedFiles=no no
longer stamps a clean source over a payload file no commit holds. A test
builds a throwaway git tree with that setting and an untracked payload
file and reads the real status.

Requirement 9 of the host-safety spec states the whole-tree ceiling over
a chain of nested sessions, and the stop of a group named for another
session only where it is in this session's tree and its recorded agent
has ended.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The GIT_ scrub moves into one fixture both source-ref test classes use,
so the archive cases' git commands no longer follow a hook's GIT_DIR.
Requirement 9 names a heavy command, not a build in the parent, as what
a shared ceiling would let end a nested agent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The shared fixture clears git's location variables through
spec/git_env.py, points global and system config at an empty file, and
holds the one identity-pinned git helper the source-ref tests use. The
dirty read passes each payload path relative to the kit rather than as
an absolute pathspec. Requirement 9 says what a command does where the
tree's ceiling cannot be put on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings November 20, 2026 02:31
@ptr727

ptr727 commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 859b62e9460c1360ea8705246fc5c2c2844b631c, the content this pull request carries at that commit against develop, and it recorded 4 findings.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 44 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8b8d9b0 and 859b62e.

Files selected for processing: 3

  • host-setup/agent-safety/README.md
  • host-setup/agent-safety/claude/install.py
  • host-setup/agent-safety/claude/test_install.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Approval should wait because Requirement 9 hinges on unverified live nested claude -p behavior—including session-ID inheritance and SessionEnd ordering—that cannot be established from the repository snapshot and requires the maintainer’s runtime probe.

No open issues 🎉

What changed in this PR

This pull request improves Claude agent-safety source tracking and documents session-tree containment behavior.

Changes:

  • Includes all untracked files and uses kit-relative paths when computing dirty source stamps.
  • Adds isolated temporary Git fixtures and regression coverage for untracked payload detection, with external DEPLOYED_DATA coverage still needed.
  • Expands requirement 9 with nested-session tree ceilings and bounded orphan cleanup behavior.
  • Includes documentation tense and test-fixture docstring corrections to address.
File Description
host-setup/​agent-safety/​README.md Documents nested-session tree ceilings and bounded cleanup of orphaned groups.
host-setup/​agent-safety/​claude/​test_install.py Adds isolated Git fixtures and regression coverage for hidden untracked payloads.
host-setup/​agent-safety/​claude/​install.py Makes dirty-source detection include all untracked payload files and use kit-relative pathspecs.

Review effort: Lite

@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.05%. Comparing base (b38e084) to head (859b62e).
⚠️ Report is 263 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4311      +/-   ##
===========================================
- Coverage    81.60%   79.05%   -2.56%     
===========================================
  Files           26       43      +17     
  Lines         9070    15733    +6663     
===========================================
+ Hits          7402    12438    +5036     
- Misses        1668     3295    +1627     
Flag Coverage Δ
python-3.13 79.05% <ø> (-2.56%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ptr727

ptr727 commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@ptr727

ptr727 commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

/review

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ptr727

ptr727 commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

Answering the headline of the Copilot round on 859b62e9 (#4311 (review)), which counts no finding and flags (1) item:

  1. host-setup/agent-safety/README.md requirement 9: "Approval should wait because Requirement 9 hinges on unverified live nested claude -p behavior, including session-ID inheritance and SessionEnd ordering, that cannot be established from the repository snapshot and requires the maintainer's runtime probe."

Awaiting maintainer. The requirement text states what an implementation must do, so it holds whichever way the probe comes out. The probe decides whether the Claude kit meets it. #2598's approved option asks for that nested run first, and a nested agent session is a live run outside this change's workspace. So the body hands the maintainer the exact command and the observations that tell the two cases apart, under "For the Maintainer to Run". This pull request touches host-setup/agent-safety/, so its merge waits on the maintainer's read of the diff in any case. This answer records the outcome once that run is in.

@ptr727

ptr727 commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

Deferred to #4312. The maintainer approved merging after his diff read, with the nested-session probe as his own follow-up. The requirement 9 text holds whichever way the probe comes out. An inherited id would be a Claude kit defect against it, and #4312 tracks that.

@ptr727
ptr727 merged commit 7420fe3 into develop Nov 20, 2026
14 checks passed
@ptr727
ptr727 deleted the burndown/safety-kit-stamp-req9 branch November 20, 2026 02:51
ptr727 added a commit that referenced this pull request Nov 20, 2026
…d, and Hub Pin Drift (#4315)

## Summary

Promotes `develop` to `main`. It carries these changes:

- [#4303](#4303) orders
the STANDUP.md seed push, carry commits, and secret hand-over.
- [#4304](#4304) forbids
state-changing probes and routes observed secrets to revocation.
- [#4305](#4305) routes
SIGINT and SIGTERM through one handler, bounds the child wait, and
states two stop paths.
- [#4306](#4306) holds
`pr_review.py merge` for a hosted review not registered yet.
- [#4309](#4309) reads the
branch before the tree so an empty root commit resolves its secrets.
- [#4310](#4310) watches
the merge bot's auto-merge and re-arms a disable GitHub makes.
- [#4311](#4311) counts
untracked files in the dirty stamp and states the session tree bound.
- [#4314](#4314) reports
each caller's hub pin behind the newest release as drift past a 30-day
bound.

Related issues #4308, #4312, and #4313 stay open.

Fixes #1418
Fixes #4137
Fixes #4063
Fixes #4147
Fixes #2598
Fixes #4128
Fixes #4240
Fixes #4229
Fixes #3806
Fixes #4146
Fixes #4100
Fixes #4218
Fixes #4223
Fixes #4228
Fixes #4224

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


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Repository audits now report outdated reusable-workflow pins as
advisories or drift, with advisory findings kept separate from blocking
issues.
* Merge automation can retry enabling auto-merge after the base branch
settles; unsupported target branches and refused merges are reported as
failures.
* Pull-request checks now account for a brief hosted-review registration
window before reporting checks as pending.

* **Bug Fixes**
* Empty repositories and empty root commits are handled correctly when
resolving repository secrets.
* Long-running tools improve cleanup and signal handling when
interrupted.

* **Documentation**
* Updated guidance for repository setup, review handling, workflow
automation, and safe verification practices.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

2 participants