Skip to content

feat(session-flow): keep the away report current from the Stop hook - #17436

Merged
kyle-sexton merged 4 commits into
mainfrom
feat/17388-stop-hook-writes-report
Nov 19, 2026
Merged

kyle-sexton merged 4 commits into
mainfrom
feat/17388-stop-hook-writes-report

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Refs: #17388

Summary

With the Bash sandbox on, a sandboxed away.py refresh cannot write the away state under the plugin data directory, so during an absence the report's refused-actions and external-actions blocks went stale with no error. Hooks run outside the sandbox (sandboxing, Filesystem isolation), so the Stop hook now writes those blocks itself. This is option A of the approach comment on #17388, which the owner chose. The state location, the hooks' read path and the trust boundary are unchanged.

Fix

  • on_stop (active absence) records the transcript path, then rewrites the refused and external-action blocks (refresh(..., files=False)) before it checks the report. It hashes the report after that rewrite, so the existing "no progress since the last block, let it stop" check still ends a loop.
  • The watched-folder file scan (SCAN_BUDGET_SECONDS, 60 s, equal to the Stop hook's 60 s timeout) runs only at end and on refresh --files. The old due-time scan on the first refresh after report-by is removed, since nothing triggers it now.
  • start records report_dir, the realpath of the report's folder. write_blocks refuses a report whose folder now resolves elsewhere or that is not a regular file, so a link planted by a sandboxed command cannot redirect the hook's write. A state from before this change has no report_dir, so it gets only the regular-file check. A command that hits the refusal prints it and exits 1.
  • If the rewrite fails, the hook logs it and still runs the report check, so open items keep holding the run. Any other hook error still fails open to silence. The hook returns only block or nothing; grep -c '"allow"' plugins/session-flow/scripts/away.py prints 0.
  • The Stop note no longer asks the session to run refresh. When blocks_fresh fails, it says to keep each away marker once.
  • step-away SKILL.md and reference/rules.md, plus go-with-recommendations: no refresh while the person is away. start, end and deliver run outside the sandbox while the person is present. Re-read the report before editing it.

Verification

  • uvx --with pytest pytest plugins/session-flow/scripts/tests -q: 549 passed. New tests cover six things. The Stop hook lists a new refusal itself, with no refresh. It lists transcript external actions and auto mode denials and leaves the agent's sections untouched. It runs no file scan, which end still runs. A report it cannot write still blocks on open items. A link planted at the report or its folder is never written through, and end reports it with exit 1. An absence recorded before report_dir existed, through a symlinked folder, still ends. Each of these tests except the file-scan one failed before its fix; the file-scan test guards behaviour that already held.

  • Cost per Stop, against the 60 s Stop hook timeout. The test was 7 timed runs of the whole away.py hook Stop process, on one WSL2 Linux host. Input was a real 21 MB session transcript plus 31 MB of subagent transcripts (657 tool uses), read in place, never copied or committed. The absence start was backdated so every record counts. That is the worst case: the whole session falls inside the absence.

    Script Median Min Max
    main (no rewrite) 49 ms 47 ms 50 ms
    this branch (scan, redaction, block rewrite) 273 ms 258 ms 347 ms

    The change adds about 224 ms per Stop at the median. The run listed 36 external actions, which shows the full scan ran.

  • scripts/run-ruff.sh check clean; check-skill.sh on session-flow skills passes, 0 errors; validate-cases.py on session-flow evals: no FAIL; the pre-push check-affected passed.

Remaining

These done-when items of #17388 are not covered here. The owner's choice of option A leaves them as written:

  • "away.py keeps its state in a location writable inside the Bash sandbox (or has a documented fallback)": the state stays under the plugin data directory.
  • "The hooks read state from the same location": unchanged, since the location did not move.
  • "With the sandbox on, start and refresh run without leaving the sandbox, shown by a live run": start, end and deliver still run outside the sandbox while the person is present. refresh is no longer needed during an absence. No live sandboxed run was made.
  • "The state location is covered by a test": not applicable while the location is unchanged.

Related

🤖 Generated with Claude Code

During an absence the Stop hook now rewrites the report's refused-actions
and external-actions blocks itself before it checks the report. Hooks run
outside the Bash sandbox, so the session no longer has to run
`away.py refresh` from a sandboxed command that cannot write the state.
The watched-folder file scan stays with `end` and `refresh --files`, out
of the Stop hook's 60 s timeout. The Stop note no longer asks for a
refresh, and a hook error still leaves the stop silent.

Refs: #17388

Co-authored-by: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 19, 2026 14:24
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T14:26:51.341570Z 7d90475 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7d90475c9b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…otcha

The skill body stated that hooks run unsandboxed, an upstream behavior
the skill-bodies rule says to leave to the pointer beside it. Keep only
our decision that the Stop hook keeps the report current.

Refs: #17388

Co-authored-by: Claude Opus 5.5 <[email protected]>

@github-actions github-actions Bot 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.

claude-security-review: 1 inline finding(s) on 7d90475c9b61fc1ec1b7337e53838634135ed521; the summary is in this lane's pull request comment.

claude-lane: claude-security-review

Comment thread plugins/session-flow/scripts/away.py Resolved
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 33d44842f9364b58794573cd010ad7c5cbd3dac5: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #17436, incremental 1bd807a2..33d44842

No new security findings. This lane already reviewed earlier heads of this pull request, so the review was blocking only: just CRITICAL and IMPORTANT findings were in scope, and SUGGESTION findings were dropped. I read every hunk of both files on the incremental list (away.py and tests/test_away.py).

What changed and what I checked

Fallback for older states in guarded_report (away.py#L842)

  • When a state has no report_dir, the expected folder is now realpath(report.parent) instead of abspath. For those states, the folder check compares the path with itself, so it is dropped.
  • That leaves one gap: a .work/away folder swapped for a symlink would still be written into. It only affects absences that were already running when the plugin was upgraded. Every absence started on this version records report_dir at start.
  • A sandboxed session cannot strip report_dir to reach that fallback. The state lives under the plugin data directory, and the PR's own premise is that the sandbox cannot write there.
  • The leaf check (lstat + S_ISREG) still applies, so a symlink planted at the report itself is still refused. The secret-read case from the earlier finding stays closed.
  • The owner's reply on the resolved thread at original line 842 states this trade-off as a decision ("drops the folder check for these older states only"). The thread is marked lines changed since resolution: no at this head, so I am not raising it.

main now also catches OSError (away.py#L1215-L1217)

  • This only affects the CLI commands. The hook path returns from run_hook before reaching this point (L1195-L1196), so hook behaviour is unchanged: it fails open to silence, and no path returns allow.
  • The stderr message carries only the exception text (a path and "left untouched"), not file contents, so nothing leaks.

Tests. The new test checks two things: end refuses a planted link with exit 1 and no traceback, and the secret file and the outside folder are left untouched. A second new test covers the older-state fallback. Neither adds any attack surface.

Other notes

  • Embedded text: none found in the PR context or the settled threads.
  • Spend: no billing impact. This push adds no runs.
  • Trusted paths: none of the changed files match a trusted-path glob.

critical-findings: 0

@github-actions github-actions Bot 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.

claude-review: 2 inline finding(s) on 7d90475c9b61fc1ec1b7337e53838634135ed521; the summary is in this lane's pull request comment.

claude-lane: claude-review

Comment thread plugins/session-flow/scripts/away.py Resolved
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 33d44842f9364b58794573cd010ad7c5cbd3dac5: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Code review: Stop hook keeps the away report current (#17436), incremental, blocking only

This lane has already reviewed earlier heads of this PR, so this pass reports blocking findings only. It covers the change from 1bd807a297 to 33d44842f9, which touches away.py and test_away.py.

No blocking findings.

What changed:

  • guarded_report (away.py:842): when a state has no report_dir, the expected folder is now os.path.realpath(report.parent). The folder check is dropped only for absences started before this change; the S_ISREG leaf check still applies. This fixes the earlier finding that a symlinked path refused every write.
  • main (away.py:1215): now catches OSError along with AwayError. A refused rewrite in end prints away.py end: … left untouched and exits 1 with no traceback.
  • Tests:
    • The planted-link test now also checks that end exits 1, prints no traceback and writes nothing through the link.
    • A new test checks that a state with no report_dir, reached through a symlinked folder, finishes end with a filled files block.

The owner's reply on the away.py:842 thread states a decision, and this head carries it out, so that thread is not raised again.

end still moves the state to ended before refresh. If that rewrite fails, a second end exits 0 at the ENDED check without refreshing. Now that the error is reported, this is not blocking, and because this pass is blocking only I am not posting it as a finding.

Closing issue: the PR says Refs: #17388 and closes no issue, so I checked no acceptance criteria.

Loosened checks: Loosened-check verdict: fail (default; no wrapper line); patterns: 0. The prompt had no loosened_check_decision_record: line, so I did not check the citation requirement.

Verification: I ran nothing. The suite count of 549 passed is the author's claim and I have not checked it.

Verifier dropped 0 of 0 candidates.

Review fixes for the Stop hook's report rewrite:

- Refuse to rewrite the report when its folder resolves elsewhere than
  the one recorded at start, or the report is not a regular file, so a
  link a sandboxed command plants cannot redirect the unsandboxed hook's
  write or copy a linked file into the report.
- A failed rewrite is logged and the Stop hook still runs its report
  check, so open task items keep holding the run.
- Drop the due-time file scan, which nothing triggers now that the
  session runs no refresh during an absence; the scan stays with end
  and refresh --files.
- go-with-recommendations no longer runs refresh during an absence.

Refs: #17388

Co-authored-by: Claude Opus 5.5 <[email protected]>
@kyle-sexton

Copy link
Copy Markdown
Member Author

Review round 1 on 7d90475, fixed in fb42d7d and 1bd807a:

Finding Source Classification Action
Skill body restates upstream sandbox behavior ("unsandboxed") Codex, inline VALID Restatement removed (fb42d7d)
The Stop hook's rewrite follows a planted symlink claude-security-review, inline VALID (IMPORTANT) guarded_report checks the folder's realpath against report_dir recorded at start and refuses a non-regular file; covered by a test with two cases (1bd807a)
A refresh failure drops the open-items hold claude-review, inline VALID Only the rewrite is guarded; the check still runs; test updated (1bd807a)
The due-time scan is unreachable and the changelog does not say so claude-review, inline VALID files_due path removed; fragment updated (1bd807a)
go-with-recommendations still runs away.py refresh during an absence claude-review, summary VALID The refresh call is replaced by "the Stop hook keeps the report's script-owned blocks current" (1bd807a)

session-flow scripts suite: 548 passed. ruff clean.

@github-actions github-actions Bot 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.

claude-review: 1 inline finding(s) on 1bd807a2971bc22092f5d9d819913f773e15f988; the summary is in this lane's pull request comment.

claude-lane: claude-review

Comment thread plugins/session-flow/scripts/away.py Resolved
An absence started before report_dir existed compared the report
folder's realpath with its abspath, which differ on any symlinked path,
so every rewrite was refused and end died with a traceback after moving
the state to ended. With no recorded folder the check now falls back to
the folder's realpath, keeping the regular-file check. An OSError from
a command now prints as an error and exits 1.

Refs: #17388

Co-authored-by: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit a54dfa1 Nov 19, 2026
63 checks passed
@kyle-sexton
kyle-sexton deleted the feat/17388-stop-hook-writes-report branch November 19, 2026 15:04
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 6, survived 1, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 86%; mutation score 86%.

File Killed Survived Timeout No coverage Invalid Not run
plugins/session-flow/scripts/away.py 6 1 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/session-flow/scripts/away.py:1078 ROR unclassified none

The run's summary has the full report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant