feat(session): record every guard intervention - #112
Merged
Conversation
Five guards act on a turn and none of them left a trace beyond a log line, so "does the watchdog ever fire?" and "does the loop guard catch anything real?" had no answer — and the next threshold would have been another argument. Every trip is now written to its own table and published as a live event, and `redcode debug guards` reads it back. Deliberately not a durable session event: this is evidence about the run, not part of the conversation. Claude-Session: https://claude.ai/code/session_01GnxRKZmMXe7qcqVXFKwdkJ
Two of these are the cost of the change: `session.next.guard.tripped` has to be in the public wire manifest, and `redcode debug guards` shows up in the help snapshot. The third is not mine but blocked this branch: the timeline offset test waited a fixed three animation frames, which is plenty on a quiet machine and not enough on a loaded Windows runner. It now waits for the condition, letting a macrotask run between frames — a loop of nothing but frames starves the observer callback it is waiting for. Claude-Session: https://claude.ai/code/session_014XwJPDhq1ahcm3rd454WzQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
0.14.0 ships five guards over the turn — the inactivity watchdog, a deadline on every tool, the
loop guard, the graduated step budget, and bounds on the calls around a turn. Every threshold in
them (300 s of silence, 600 s for a tool, three identical calls, two steps of grace) was chosen by
argument, because there was nothing to measure. And each intervention left only a
logWarningin the server log, so the obvious questions had no answer: does the watchdog everfire? does it fire when it should not? did the loop guard ever catch a real loop, or does every
timestamped tool output escape it?
What this adds
session_guard_trip: which guard, what it acted on, whatit did (
warn/correct/stop), and the detail the policy module already produces.session.next.guard.tripped, so the TUI, plugins and the SDK can react now.Deliberately not durable: this is evidence about the run, not part of the conversation, and
the durable manifest is the session's source of truth rather than a diagnostics channel.
redcode debug guards [--days 7] [--limit 20]prints counts per guard andaction, loudest first — what fires most is what most needs its threshold questioned — then the
most recent trips. When nothing fired it says so in words, because an empty table reads as "no
data collected", which is a different answer.
Recording can never break a turn: a failed write is logged and the intervention still happens.
Verification
recent()withthe right guard, action, subject and session, and aggregates through
summary().packages/core/script/migration.tsrather than hand-written —my hand-written one passed my own test and failed the repo's schema-drift check, which is exactly
what that check is for.
packages/core1143 pass;packages/redcodesession suite 450 pass, with the one failure thismachine reproduces on unmodified sources (the feat(session): end a turn that has stopped producing anything #103 watchdog test, 60 s timeout under local load).
One thing worth knowing
An unrelated edit to
packages/llm/src/schema/messages.tswas sitting uncommitted in my workingtree from before this branch and got swept into the first commit; it breaks
tool-runtime.tstypechecking. It is not part of this change and has been reverted here — flagging it in case it was
someone's work in progress.
https://claude.ai/code/session_01GnxRKZmMXe7qcqVXFKwdkJ
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.