Skip to content

fix(guards): line-delivery edge cases left out of 6271 - #8125

Merged
kyle-sexton merged 2 commits into
mainfrom
work-resolve-issue/issue-6273-39105894439-1
Oct 19, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
work-resolve-issue/issue-6273-39105894439-1

Conversation

@melodic-automation-lanes

@melodic-automation-lanes melodic-automation-lanes Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Refs: #6273

Hold: a human merges this

Summary

Opened by the work-resolve-issue lane. The run's own summary:

Fixes cases 1-3 of #6273 in context-guard. A restatement now absorbs earlier approach lines and keeps only a threshold's action sentence. The held-turn suggestion uses the same merge. The crossing toast shows before the snapshot write at session.measure. The new tests have not been run here.

Not verified

  • The mod test file (context-guard.test.ts, the only one left after the rate-limit-guard revert) was not run. run-test-file refuses it (it uses claude plugin test, not vitest), and the lane allows no other runner. The tests were checked by reading only. Left to the PR's CI (scripts/test-plugin-mods.sh).
  • Case 2 is reachable (a held turn with an unshown crossing, then compaction and a measure), so it was fixed with a test and not closed.

Fix

  • plugins/context-guard/hooks/register.tsx: new mergeRestated, used by takeLines and turn.complete; threshold events can render action-only; session.measure runs showPending first and queueWrite in a finally
  • plugins/context-guard/hooks/context-guard.test.ts: tests for cases 1 (approach, threshold action sentence), 2 and 3, plus a gate on process.run in the stub world
  • .changes/context-guard/issue-6273-line-delivery-5c2e8a41.md: patch fragment

Verification

The run reports:

Left out: the items under Not verified.

Related

#6273

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 46dfcfbe63c3214a60dbc19d86e86ecc0c95f151: 0 finding(s), 0 as inline comments.

No security issues found in the incremental change (a3adb0c..46dfcfb).

The only file changed is plugins/context-guard/hooks/context-guard.test.ts. The change:

  • adds test-harness stubs (onToast, surfacesFail);
  • replaces a fixed 20 ms sleep with a bounded wait on the toast promise (2 s timeout, timer cleared in finally);
  • adds a test that a failing toast step still runs the snapshot write.

It touches no production code, guardrails, instruction surfaces, secrets or trust boundaries. The skip gate for no security-relevant surface applies. I did not consult the instruction exception register, because the diff removes or softens no standing instruction.

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 46dfcfbe63c3214a60dbc19d86e86ecc0c95f151: 0 finding(s), 0 as inline comments.

No findings. I reviewed only the incremental change to plugins/context-guard/hooks/context-guard.test.ts, since a3adb0c0.

  • Slow snapshot test: the fixed 20 ms sleep is now a wait on an onToast promise, raced against a 2 s timeout that rejects with a clear message. The timer is cleared in finally. This removes the timing flake and still pins that the toast arrives while the snapshot write is held. On the failure path the held gate is never released, which only matters if the test is already failing.
  • New test, a failing toast step still runs the snapshot write: surfacesFail makes session.surfaces throw. The only caller is operatorHolds (register.tsx:415), reached through showPending in the session.measure handler (register.tsx:792-802). The try/finally there still queues the write. Without the finally, the run count would not rise, so the test would fail before the fix. The .catch(() => {}) on measure is harmless, because the handler's own .catch(($, e, next) => next(e)) already absorbs the error.
  • Stub changes: the onToast and surfacesFail fields are optional, so existing tests are unaffected.
  • Not run: I did not run the tests. These mod tests use claude plugin test, and I only traced the new test against the source by reading.

@kyle-sexton

Copy link
Copy Markdown
Member

This was generated by AI: an independent fresh-context review requested by the owner in an attended backlog-shaping session on 2026-10-18. The owner merges this PR after the findings are fixed.

Review: PR #8125 fix(guards): line-delivery edge cases left out of 6271

PR: #8125 (head a3adb0c, merge-base 6498194)
Source issue: #6273 (Decision recorded 2026-10-18, Agent Brief 2026-10-18)

Criteria read: REVIEW.md, AGENTS.md Code Review Rules, .claude/rules/pr-body-contract.md, issue #6273 decision and Agent Brief, testing:test-value. Not read: .claude/rules/mod-authoring.md and hook-precision README (no hook-precision false-positive fix in scope: these mods block nothing).

Verdict: FIX

The context-guard half (cases 1-3) is correct, and its four new tests are red-first: I ran them against the base register.tsx and all four fail (287 pass / 4 fail), then pass at head (291 / 0). The rate-limit-guard half (case 4) does not meet the decision. Its test passes on the unfixed code, so the "red-first test using a throwing ui.log stub" the owner asked for does not exist.

Safety (guard behavior)

  • No blocking path. context-guard and rate-limit-guard only show notices, toasts, lines for Claude and snapshots; nothing in the diff denies or allows a command, so no blocked command can now get through.
  • New suppression. mergeRestated (plugins/context-guard/hooks/register.tsx:478-487) now also drops approach lines and threshold verdict lines recorded before a pending restatement. Those events can only predate a compaction or reload, so they are stale. A threshold's action sentence is kept (actionOnly), and one with an empty sentence is dropped, so no empty line is sent. The merge is idempotent (it runs in turn.complete and again in takeLines). I found no current line that it hides.

Findings

IMPORTANT

  1. The case-4 test cannot fail, and the case it targets was not shown to occur. plugins/rate-limit-guard/hooks/rate-limit-guard.test.ts:821-838, plugins/rate-limit-guard/hooks/register.tsx:311-320.
    Evidence (run this session in a scratch copy): with base register.tsx and the PR's tests, rate-limit-guard gives 138 pass / 0 fail, so the new test passes without the fix. I added probe tests: the stub threw once (threw: 1), and a { deny } stub had the same effect. In both cases the base code still delivered the 7d transcript line, both toasts, and a notice row naming both windows. The head code never logged window change not logged. The harness does not pass a failing ui.log handler on to the module as a throw, so neither the old outer catch nor the new inner one is ever reached.
    This misses the Agent Brief's criterion ("Each case has a red-first test") and the 2026-10-13 decision ("a red-first test using a throwing ui.log stub"). The decision assumed a throwing stub could reach the module, and the probe shows it cannot. Neither review lane ran the tests (both say so), so neither caught this.
    Fix (needs the owner, because it departs from the recorded decision): put the probe result on fix(guards): line-delivery edge cases left out of #6271 #6273 and pick one option. (a) Keep the per-item try/catch as defensive code, add cant-fail-ok: <why> to the test or delete it, and say in the PR body that no red-first test is possible. (b) Revert the rate-limit-guard change and close case 4 on the evidence that the harness never passes a ui.log failure on to the module. Either way, keep Refs: rather than Closes.
    Confidence: high

SUGGESTION

  1. The rate-limit-guard fragment claims a fix for a failure that was not shown to occur. .changes/rate-limit-guard/issue-6273-flush-toasts-7b4d1e92.md:7. It reads as a fix users will notice. Reword it to "hardening: ..." under option (a), or delete it under option (b).
    Confidence: high

  2. The case-3 guarantee "a failing toast step still cannot skip the write" has no test. plugins/context-guard/hooks/register.tsx:794-800 (try/finally). The new test (plugins/context-guard/hooks/context-guard.test.ts:982-995) covers only the ordering. Add a test where the showPending step throws (for example a session.surfaces or session.id stub that throws on the measure call) and assert that w.runs grew by one snapshot run. Its expected value comes from the Brief's desired behavior 3.
    Confidence: medium (the code reads as correct; only the test is missing)

  3. The ordering test waits on a 20 ms timer. plugins/context-guard/hooks/context-guard.test.ts:990. Everything before the gate is promise work, so it passes today, but a fixed sleep makes the test depend on timing. Have the ui.toast stub resolve a promise and await that promise (with a timeout) instead of sleeping.
    Confidence: medium

  4. Advisory: the action sentence comes before the verdict it belongs to. In the test at plugins/context-guard/hooks/context-guard.test.ts:1049-1058, Claude reads context-guard (operator setting for a threshold): handoff. before dumb zone (3 of 3, compacted). Consider emitting actionOnly sentences after the restatement inside mergeRestated (register.tsx:482-486) so the verdict leads. This is reviewer opinion, not a rule.
    Confidence: low

  5. The outer catch's logOnce is still unguarded. plugins/rate-limit-guard/hooks/register.tsx:327. If ui.log could throw (the premise of the change), this call would still escape, so the "never throws" claim at register.tsx:298-299 would not hold. This matters only under option (a) of finding 1: wrap it the same way, or drop the premise.
    Confidence: medium

Checked and fine

  • Decision match. Case 1: approach lines are absorbed and the threshold's action sentence is kept (test at 1049, red-first). Case 2: reachable, and fixed in turn.complete (register.tsx:819) with a red-first test. Case 3: the toast shows first and the write runs in a finally (red-first test). One PR covers both register.tsx files, and the body has Hold: a human merges this.
  • Scope. No creep. The only extra is a gate on the test world's process.run (context-guard.test.ts:45-46, 111-113). It is needed by the case-3 test and leaves the other 287 tests unchanged.
  • CI. Every check passes on a3adb0c. The mod tests ran under check-plugins (context-guard 291/0, rate-limit-guard 138/0); test-node, test-python and test-bash were skipped as not affected. pr-review and pr-review-security each reported 0 findings, and neither ran the tests. Mergeable: CLEAN. Since the merge-base, main has touched these plugins only through a release commit (ac4107e).
  • Acceptance criterion "scripts/run-test-file.sh passes on both mod test files". The lane could not run it, but claude plugin test passed in CI and in my local run.

Coverage: all changed files reviewed.

Owner decision (2026-10-18), case 4: remove the ui.log try/catch and close case 4. Probe tests show the mod runtime never lets a throwing or denying ui.log reach the module, so no failing-first test can exist. The owner chose to remove the guard rather than keep defensive code nothing can trigger.

@kyle-sexton kyle-sexton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This was generated by AI: independent review requested by the owner in an attended backlog-shaping session on 2026-10-18. Each finding is its own thread so the PR-fix lane can address it. The owner merges this PR after the fixes.

…t write

The mod runtime never lets ui.log throw into the module, so the per-item
try/catch in rate-limit-guard's flushToasts guarded nothing and its test
passed without it. Restore the plain log call and remove that test and
its changelog fragment.

context-guard: wait on the toast itself instead of a fixed 20 ms timer,
and add a test that a failing toast step still runs the snapshot write.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ9amjLiLKnwj4WGMRcofR
@kyle-sexton

Copy link
Copy Markdown
Member

Decision recorded.

Question: Do the two open suggestions block (PRRT_kwDOTCGFQM6tpbxq: add a test where the toast step throws; PRRT_kwDOTCGFQM6tpbxs: advisory event ordering)? Options: (a) fix the first, resolve the second, then merge; (b) resolve both and merge.
Answer (owner, 2026-10-19): "Go with recommended", which is (a): add the test for the case-3 try/finally where the toast step throws, resolve the advisory thread, then merge.

Next: Attended Build adds the test.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 19, 2026
Merged via the queue into main with commit 525ad50 Oct 19, 2026
50 checks passed
@kyle-sexton
kyle-sexton deleted the work-resolve-issue/issue-6273-39105894439-1 branch October 19, 2026 19:20
kyle-sexton added a commit that referenced this pull request Oct 20, 2026
…from main

#8125 added three compaction tests that clear the figures after compact()
and expected the old zone restatement. With this PR's intent (#7883), a
compaction with no figures says the reading is unavailable, so those
expectations now name UNAVAILABLE.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WyWcv2NwzrPQ4dChfwFjM7
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.

1 participant