Skip to content

perf(session-flow): clear a delivered absence's away state - #17396

Merged
kyle-sexton merged 4 commits into
mainfrom
perf/17389-clear-delivered-away-state
Nov 19, 2026
Merged

kyle-sexton merged 4 commits into
mainfrom
perf/17389-clear-delivered-away-state

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Closes #17389

Summary

A delivered absence's state stayed under <plugin data>/away/<session>/, so once any absence had run, every later session's PermissionRequest, Elicitation, Stop and UserPromptSubmit hook started Python instead of exiting in the shell gate of hooks/run-away-hook.sh. away.py deliver now removes the session's state and away/ itself once it is empty, so idle hooks return to the cheap path.

Fix

  • deliver takes the session lock, refuses an active absence as before, then removes state.json, refused.jsonl, the end copy report.md and (POSIX) the lock file while still holding the lock; after releasing it, it removes the session dir and away/, each with rmdir so a dir with anything unexpected in it stays.
  • The report survives. A report in the launch checkout's git-ignored .work/away/ stays where it is. A report kept inside the state dir (not-git-ignored case), or the end copy when the original is gone, moves to <plugin data>/away-reports/<stamp>-<session8>.md first. deliver now prints report=<lasting path> and the step-away SKILL.md tells the agent to give the person that path.
    • Basis for moving rather than keeping the dir: keeping it would leave away/ non-empty, so the not-git-ignored case would never regain the cheap path, which is the issue's goal (run-away-hook.sh:8 gates on -d "$DATA/away"). away-reports/ is a sibling the gate does not look at.
  • deliver also sweeps other sessions' already-delivered state (left by the version before this one), each only when its lock is free (locked(..., wait=0)); a held lock leaves that dir in place.
  • A second deliver, or one with no state, prints status=none and exits 0. start after deliver begins with fresh state, refusals included.
  • The hooks are unchanged: still silent without an active absence, and grep -c '"allow"' plugins/session-flow/scripts/away.py is 0.
  • The launch-warning settings reads moved from away.py to scripts/away_launch.py, a separate concern, so away.py stays under the repository's 1000-line size reference (the pre-push size check failed without it).

Retention: reports in away-reports/ are kept until the person deletes them; nothing prunes them.

Verification

  • uvx --with pytest pytest plugins/session-flow/scripts/tests -q -p no:cacheprovider: 548 passed. New or changed cases: test_deliver_once, test_deliver_moves_a_report_kept_beside_the_state, test_deliver_keeps_a_git_ignored_report_in_place, test_deliver_keeps_another_sessions_absence, test_deliver_sweeps_an_old_delivered_absence_unless_its_lock_is_held, test_start_after_delivery_begins_new_absence, and the deliver case of test_hook_note_command_names_data_root. All 7 fail against the previous away.py.

  • scripts/run-ruff.sh check on the three Python files: clean. No shell changed.

  • Idle hook cost, measured with printf '{"session_id":"00000000-0000-0000-0000-000000000000"}' | /usr/bin/time -f '%e s' env CLAUDE_PLUGIN_DATA=<dir> CLAUDE_PLUGIN_ROOT=<plugin> node <plugin>/hooks/exec-bash.mjs <plugin>/hooks/run-away-hook.sh Stop, after one start/end/deliver in a fresh session-flow-* data dir. Before = data dir delivered by the old code (away/ remains); after = data dir delivered by this code (away/ gone). Runs interleaved on the same host, which was under load, so absolute values are above the issue's 0.09 s / 0.02 s:

    Round Before After
    1 0.75 s 0.04 s
    2 0.18 s 0.04 s
    3 0.21 s 0.04 s

Related

🤖 Generated with Claude Code

kyle-sexton and others added 2 commits November 19, 2026 01:32
deliver now removes the session's away state (state.json,
refused.jsonl, lock and the end copy of the report) and then away/
itself when it is empty, so the away hooks' shell gate exits before
Python again in later sessions. A report kept inside the state dir
moves to <plugin data>/away-reports/ first, and deliver prints where
the report lasts. Removal runs under the session lock; other sessions'
delivered state left by an earlier version is swept only when its
lock is free.

Co-authored-by: Claude Opus 5.5 <[email protected]>
The settings reads behind the launch warnings (managed, user, project
and local files) are their own concern; moving them out keeps away.py
under the 1000-line size reference.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 19, 2026 06:43
@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-19T06:46:02.936915Z 900dddd 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: 900dddd764

ℹ️ 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".

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 5ce3059e7eb87373bc523cff9a282686e2a7d767: read 6 of 6 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #17396 (head 5ce3059)

I found no security issues. I read every hunk of all 6 changed files in .claude-lane/pr.diff. The lane had already reviewed an earlier head, so this review was blocking only: it reports CRITICAL and IMPORTANT findings only.

What I checked

  • What deliver deletes. _clear_held unlinks only fixed names inside the session directory: report.md, refused.jsonl, state.json and, on POSIX, lock (away.py#L896-L898).
    • state["report_path"] goes only to realpath, exists and the return value. It is never deleted or moved, so a changed state file cannot turn delivery into a delete of some other file.
    • _remove_dirs uses rmdir, which only removes empty directories.
    • The archive path is built from the data root, a UTC timestamp and the session name, which has already passed SESSION_RE.
  • The sweep of other sessions. sweep_delivered skips any entry whose name fails valid_session or has no state.json. It takes each lock with wait=0 and clears an entry only when its status reads DELIVERED. An active or ended absence of another session is left alone, so that session's hook refusals stay in place (test_deliver_keeps_another_sessions_absence covers this).
  • The refusal guard. cmd_deliver still calls move(state, Status.DELIVERED) under the lock. MOVES allows DELIVERED only from ENDED or DELIVERED (away.py#L92-L97), so an active absence cannot be removed early. A delivered absence already made the hooks silent before this change, so removing its state does not weaken any refusal. A new start begins with no refusals carried over from the last absence.
  • The away_launch.py move. _setting, managed_base, managed_files, _managed_setting and launch_warnings moved over unchanged from away.py. They read settings files and write nothing.
  • The tests. test_away.py is test-only. It patches Path.unlink inside a monkeypatch.context() to simulate a delivery that stops partway.
  • Other areas. The change touches no manifest, workflow, hook script, trust control or trusted path. It deletes no guardrail from a standing instruction: the SKILL.md and README edits only add a sentence saying where the report lasts. It adds no spend.
  • Settled thread. The thread on away.py lines 896-897 is resolved and marked lines changed since resolution: no. I found no new problem on those lines.
  • Prior findings. The lane's earlier summary at 158df6a had no findings, so nothing is restated.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 5ce3059e7eb87373bc523cff9a282686e2a7d767: read 6 of 6 changed file(s); 0 finding(s), 0 as inline comments.

No blocking findings. This lane already reviewed an earlier head (158df6a493), so this review was blocking only and drops advisory findings. I read all 6 changed files in .claude-lane/pr.diff in full. I also read the unchanged code the changed lines call in away.py: locked, read_state/write_state, move and MOVES, cmd_start, cmd_end, and the UserPromptSubmit hook.

What checks out

  • Delivering from each state.
    • From ended, deliver checks the move under the lock. It then removes state.json, refused.jsonl, the end copy and, on POSIX, the lock file before it releases the lock.
    • From active, the move is refused, so an absence still in progress keeps its state.
    • With no state, or on a second deliver, it prints status=none and exits 0.
  • The report survives (away.py#L889-L901).
    • When the report isn't git-ignored it sits beside the state (inside), so it moves to away-reports/.
    • A git-ignored report under .work/away/ stays in place, and only the end copy is removed.
    • When the original report is gone, the end copy moves to away-reports/ instead.
  • Retrying an interrupted delivery is unchanged since the settled thread, which stays settled.
  • The sweep only touches a valid session dir that has a state.json and is already delivered, and only when its lock is free (wait=0). It logs and skips the OSError/ValueError errors it catches, and a test covers the case where the lock is held.
  • The away_launch.py split is a move with no edits. Nothing else under plugins/ imports the moved functions from away, and the tests now target away_launch.
  • The hooks still return nothing when there is no state or the absence is delivered (away.py#L1079).

Closing issue #17389

  • Deliver removes the state. Met. test_deliver_once and test_deliver_moves_a_report_kept_beside_the_state cover it.
  • No away/<session> dir remains. Met, covered by assertions that away/ no longer exists.
  • Idle hook cost measured in the PR. The author recorded 0.04 s against 0.18–0.75 s on a host under load. I could not run the measurement, so these numbers are the author's claim and unverified.
  • Tests cover the cleanup and the report stays readable. Met. The tests read the kept report back after deliver. Reports in away-reports/ are kept until the person deletes them, and the PR states that retention.

Verification: I ran nothing. The author's "548 passed" and "549 passed", and their ruff results, are their claims and unverified.

Other notes

  • No plugin manifest changed. The changelog fragment's bump: patch fits a behavior fix.
  • Loosened checks: no existing assertion is weakened. The test_deliver_once and test_hook_note_command_names_data_root assertions changed from expecting delivered status to expecting the state dir to be gone, which matches the new behavior the issue asks for. Loosened-check verdict: fail (default; no wrapper verdict or patterns lines); patterns: 0. The prompt had no loosened_check_decision_record: line, so I did not check the citation requirement.
  • Spend: none.

Verifier dropped 0 of 0 candidates.

A deliver interrupted after the report moved to away-reports/ but
before state.json was removed left the state pointing at the old path,
so a retried deliver reported a report path that no longer existed.
Write the archive path to the state before the move, so a retry names
where the report went.

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

Copy link
Copy Markdown
Contributor

Lane run report

Field Value
Activity pr-refine/fix-docs
Model rung 0
Leg base
Run job success
Activity step success
Commits pushed none (read lane)
Run 44476474452

Failed GitHub API calls

Method Path Status
GET /repos/{repo}/git/ref/tags/* 404

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 19, 2026
…vered-away-state

# Conflicts:
#	plugins/session-flow/skills/step-away/SKILL.md
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit c0f6ac6 Nov 19, 2026
46 checks passed
@kyle-sexton
kyle-sexton deleted the perf/17389-clear-delivered-away-state branch November 19, 2026 08:47
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 19, 2026
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.

session-flow: remove a delivered absence's away state so idle hook cost returns to the cheap path

1 participant