Skip to content

feat(session-flow): replace the detached observer with a live-check mod and catch-up - #18976

Merged
kyle-sexton merged 4 commits into
mainfrom
feat/session-flow-observer-mod
Nov 25, 2026
Merged

kyle-sexton merged 4 commits into
mainfrom
feat/session-flow-observer-mod

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Refs: #18959

Summary

The session-flow observer becomes a hooks module with live checks plus a session-start catch-up, and the detached 24-hour transcript tailer is retired in the same change (ADR 0052, one implementation per behavior). This leaves #18959 open for its last acceptance criterion: measuring the end-of-turn trigger's cost on one real working session before choosing its default.

Fix

  • Live checks (plugins/session-flow/hooks/register.tsx, logic in observer-live.ts): on the main thread, every 6th model step of a turn (observer_step_check, default on), and at the end of each tool-using turn when observer_turn_end_check is on (default off until measured). A check is a $.model.fork with only a prompt, so it has no tools and no transcript. It runs one at a time per session; a reply that arrives after the next turn started, or after the session ended, is dropped as stale. The prompt allows four categories (process, decision, verification, instruction), requires a cited rule, and defaults to finding: none. A finding is redacted with $.session.redact, appended to the session's running-retro ledger, and shown as a band row: 1 Send to Claude ($.prompt.fill, append), 2 Noted, 3 Dispute, 0 Dismiss. Seen and disputed findings persist across sessions in $.store and are suppressed. Findings typed past back off the next checks 1, 2, 4, 8, then 16. Each check's outcome and token usage is appended to <plugin data>/session-flow-observer/live-<session>.jsonl.
  • Catch-up: hooks/observer-arm.sh becomes hooks/observer-catchup.sh. At an interactive start it launches observer.py one-shot, detached, for up to 2 ended sibling sessions, newest first. A session qualifies when it has been idle at least observer_idle_seconds, changed within 3 days, has no live-check file, no ledger, and has grown past its stored offset. observer.py no longer tails; it reads once from the stored offset, analyzes with the existing headless run, and exits. observer_poll_seconds and observer_max_seconds are removed. With observer_analysis_enabled off, no catch-up runs.
  • Retired: /session-flow:running-retro arm and /plugin-quality:audit arm (nothing to arm).
  • Design notes:
    • The catch-up stays a SessionStart settings hook rather than a $.process.run from the module. The hook already has the self-trigger guards, the platform shim and the Python probe. A probe showed that either launcher outlives its session (Claude Code 2.1.332: a setsid -f child of a mod's $.process.run in a claude -p --plugin-dir run kept running 41 s after exit).
    • Live checks run only in interactive sessions and never under SESSION_FLOW_OBSERVER_ANALYSIS. Headless lanes get the catch-up.
  • Docs: reference/observer.md rewritten, README, setup and running-retro skills, plugin-quality session mode, options table and cheat sheet regenerated. engines["claude-code"] is >=2.1.331, the CI pin.

Verification

  • claude plugin test plugins/session-flow: 18 pass. The tests cover the step trigger on steps 6 and 12 of the main thread only; no second check while one is in flight; stale replies dropped; the turn-end trigger off by default, on for tool-using turns, skipped on aborts; a ledger plus band finding, with Send filling the prompt; nothing filled without Send; cross-session dedup; Dispute; backoff; redaction; usage recording; and off unless enabled or in the analysis run.
  • test_observer.py (pytest 9.2.0): 104 passed, 36 subtests. It covers one-shot analysis, no re-analysis past the stored offset, catch-up selection (the current session, too fresh, too old, a live marker, an existing ledger, already analyzed, the cap of 2), the lock, and every hook guard, including analysis off. The worker applied 18 single-line mutations and each failed the suite.
  • validate-plugins.sh --only "session-flow plugin-quality": all manifests validated, all mod tests passed.

Remaining

Related

🤖 Generated with Claude Code

…od and catch-up

The observer is now a hooks module plus a session-start catch-up. Live
checks fork the main conversation (no tools, no transcript) on every 6th
model step of a turn, and at turn end when observer_turn_end_check is on,
and write at most one process fault per check to the running-retro ledger
and a band row above the prompt. Repeats and disputed findings are
suppressed, ignored findings back off, and each check's usage is recorded.

The SessionStart hook now analyzes up to two ended sessions that got no
live checks with the existing headless analysis, run once instead of a
24-hour tailer. The running-retro arm action and plugin-quality's arm
entry are retired with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 25, 2026 03:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 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-25T03:34:39.476444Z 2228904 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: 22289042d1

ℹ️ 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/hooks/register.tsx Resolved
kyle-sexton and others added 2 commits November 24, 2026 22:39
…ollow-ups

A failed analysis (timeout, API or auth error, missing claude) now records
state retained and failed_attempts in the status file. The next catch-up
retries it once over the kept observations, at most two attempts per span;
reading new bytes or a successful run resets the count. A min-lines skip is
state skipped and is not retried.

A ledger excludes a session from catch-up only when it has no status file.
With a status file the stored offset decides, so the resumed follow-up of an
analyzed session is analyzed.

Declare the files the observer suites read (test-scope), which the Test
Selection trace flagged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
After /clear or a resume no session.start fires, so a check now reads
$.session.id() itself and writes its usage file and ledger under the
current session, clearing a card left from the previous one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 6054cfa87e07ff3238653cfee0912920f6303665: read 3 of 3 changed file(s); 0 finding(s), 0 as inline comments.

Security review: incremental, e865850 → 6054cfa (#18976)

I read every hunk of the 3 files in .claude-lane/incremental.diff. This lane already reviewed an earlier head, so this pass reports only CRITICAL and IMPORTANT findings. I found no new security issues.

What I checked

  • Reply-parser regex (plugins/session-flow/hooks/observer-live.ts, L37). The old prefix (?:[-*>\s]|\*\*)* could backtrack exponentially. A ** run could match as one \*\* or as two * class hits, so a long run of asterisks in a model reply could stall the hook. The new prefix is the single class [-*>\s]*. It has no alternation, it is anchored at ^, and no m flag is set, so a failed match on a line costs at most linear backtracking over the prefix. Bold labels such as **Finding:** still match, because * is in the class. The label argument is always a hard-coded constant (finding, rule, evidence, category, at L67-L72), so no outside text reaches the pattern source. The FIELD_MAX cap and the category allowlist are unchanged. This push fixes the regex finding from the summary posted at 22289042.
  • Test (observer-live.test.ts). It adds a timing test with 5000-asterisk lines. It is a test fixture only.
  • Changelog (.changes/session-flow/feat-observer-mod-8e3a1c47.md). The prose now tells existing observer_enabled users that live step checks start on update and that observer_step_check turns them off. It removes no instruction and changes no manifest.
  • Trust controls. This push touches no workflow, token request, trusted-actor list, kill switch, merge hold or plugin manifest.

Earlier findings

The four plugin.json manifest flags in the summary posted at 22289042 concern files this push leaves unchanged. Those files sit outside this incremental scope and are not repeated here.

Usage

The live step checks the changelog describes spend the user's session model usage (subscription or prepaid API usage). That is not a cost hold.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 6054cfa87e07ff3238653cfee0912920f6303665: read 3 of 3 changed file(s); 0 finding(s), 0 as inline comments.

Code review (incremental, blocking only): live-check reply parser made linear

Blocking only. This lane already reviewed an earlier head (e8658505), so this review reports only blocking findings and manifest flag lines.

Scope. I read every hunk of all 3 files on the incremental list in .claude-lane/incremental.diff. For context I also read parseReply in plugins/session-flow/hooks/observer-live.ts at head.

Result: no blocking findings.

  • observer-live.ts field() regex. The old prefix (?:[-*>\s]|\*\*)* had two ways to match **: as one \*\* or as two * from the character class. That ambiguity makes backtracking exponential on a long run of asterisks. The new prefix [-*>\s]* matches the same strings, because the class already contains *. The pattern is anchored at ^ and the label is a literal word (finding, rule, evidence, category), so a failed match now backtracks over at most the length of the line. After the label, (.*)$ always matches within one split line, so the two \s* around (?:\*\*)? cannot backtrack badly either. Every line the old pattern matched, the new one also matches.
  • observer-live.test.ts. The new test feeds 5000 asterisks, then x, a newline, and 5000 more asterisks. It checks that the reply parses as unparsable in under 1 s, and it would fail on the old exponential pattern. The 1 s bound is wide enough that the test should not flake on a slow runner.
  • Changelog fragment. The new ### Changed entry tells existing observer_enabled users that live step checks now run and use model usage, and that observer_step_check turns them off. It matches the spend noted in the last review.

Verification. I ran nothing; this review read the code only.

Spend (not a hold). Nothing new at this head. The spend from the last review is unchanged: forked live checks and catch-up analyses on the session's model usage when observer_enabled is on.

Loosened checks. Loosened checks would be marked: fail (bundled default; the prompt has no loosened_check_verdict or loosened_check_patterns line); patterns: 0. There is no loosened_check_decision_record: line, so I did not check the citation requirement. This increment removes no tests and loosens no check.

Closing issue. The PR context has no closing-issue section, so there are no acceptance criteria to check.

Verifier dropped 0 of 0 candidates.

The label regex allowed `**` as an alternative to `*`, so a long run of
asterisks in a fork reply backtracked exponentially and could freeze the
session. `[-*>\s]*` matches the same lines in linear time. The changelog
now states that users who already enabled the observer get the live step
checks on update.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton

Copy link
Copy Markdown
Member Author

Dispositions for the review-lane findings on 2228904:

Lane Finding Disposition
claude-review arm_observer.py:91: an existing ledger blocks a follow-up Correct, fixed in f42fa04. A ledger excludes a session only when it has no observer status file; otherwise the stored offset decides (test_resumed_follow_up_of_an_analyzed_session_is_picked).
claude-security-review observer-live.ts:57 exponential backtracking on a run of * Correct, fixed in 6054cfa with the suggested [-*>\s]*. New test: a 5,000-asterisk reply parses in under a second.
claude-security-review engines >=2.1.331 Kept. scripts/test-plugin-mods.sh fails a mod plugin that declares no engines["claude-code"] floor, and 2.1.331 is the CI pin (package.json) the module was tested on.
claude-security-review observer_step_check defaults on Kept: the step trigger is the owner's decision for #18959 (Q2, "go w/ recommendations", 2026-11-24), and only the end-of-turn trigger was gated on a cost measurement. Claude usage is capacity here, not a charge (the lane also found no real charge). The changelog now says that users who already enabled observer_enabled get the step checks on update, and how to turn them off.
claude-security-review observer_poll_seconds, observer_max_seconds removed Intended: they paced and capped the retired tailer. The one-shot run is bounded by --analysis-timeout-seconds, as the lane notes. Both are listed under Removed in the changelog.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit aac921d Nov 25, 2026
50 checks passed
@kyle-sexton
kyle-sexton deleted the feat/session-flow-observer-mod branch November 25, 2026 04:09
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 4, survived 3, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 57%; mutation score 57%.

File Killed Survived Timeout No coverage Invalid Not run
plugins/session-flow/hooks/observer-catchup.sh 1 0 0 0 0 0
plugins/session-flow/hooks/observer-live.ts 0 2 0 0 0 0
plugins/session-flow/skills/running-retro/scripts/arm_observer.py 1 1 0 0 0 0
plugins/session-flow/skills/running-retro/scripts/observer.py 2 0 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/session-flow/hooks/observer-live.ts:15 ROR unclassified none
plugins/session-flow/hooks/observer-live.ts:25 ROR unclassified none
plugins/session-flow/skills/running-retro/scripts/arm_observer.py:87 ROR productive input-gap

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