Skip to content

guards: a matched warning is still lost when the tags join, a table probe or db.close() throws #371

Done

Description

@kevintseng

What happens

#358 made pre-edit-recall hold a fault from the two observations reads and still emit a matched lesson guard. Three other statements inside the same outer try still take the warning with them when they throw (same behaviour before #358):

statement on throw
sqlite_master table probe outer catch, stdout empty
PRAGMA table_info(entities) outer catch, stdout empty
Strategy 1 tags join outer catch, stdout empty
db.close() in finally outer catch, stdout empty

Reproduced through the real hook with tags renamed away and an accepted Edit guard matching the payload: outcome: error, stderr no such table: tags, stdout empty — the guard matched and the user never saw it.

The guard half is evaluated before any of these. It should not depend on them.

Related, in scripts/hooks/guard-check.js: the fire counter is written BEFORE the warning is printed, and process.exit(0) follows console.log immediately. With the counter's wait now bounded to the hook budget the warning is no longer lost under a held write lock, but it is delayed by that wait; and on POSIX, where a piped stdout is asynchronous, process.exit right after a large console.log can truncate it.

Suggested direction

  • Emit the guard block as soon as it is known (or hold every recall-side fault the way recallFault does) so no recall-side statement can cost a warning.
  • guard-check.js: print, record, then count — and end by returning instead of process.exit when output was written.
  • One shared "emit warning, record outcome, count" helper for both hooks so the order cannot drift again.

Activity

  1. kevintseng commented on Sep 20, 2026

    @kevintseng
    CollaboratorAuthor

    Measured while reviewing #358 (real scripts/hooks/guard-check.js, a real OS pipe, 400 accepted Bash guards matching the command):

    reader: | (sleep 3.5; cat)     exit=0  stdout=65536 bytes   invalid JSON (truncated)
    reader: | cat  (no delay)      exit=0  stdout=65536 bytes   invalid JSON (truncated)
    same input, pre-edit-recall    exit=0  stdout=246907 bytes  valid JSON
    

    guard-check.js calls process.exit(0) immediately after console.log. On POSIX a piped stdout is asynchronous, so everything past the 64 KiB pipe buffer is dropped: the host receives half a JSON document, the whole additionalContext is lost, exit is 0 and stderr is clean. It needs no lock and no slow reader. The threshold is roughly 215 simultaneously matching accepted guards at the 280-character message cap, so it is unlikely today, but it is silent when it happens.

    Also measured under a held write lock, time to first byte: guard-check.js 2.14 s (it counts before it prints, and the counter now waits its 2 s budget) versus pre-edit-recall.js 0.07 s (prints first).

    When this is fixed, point the POSIX slow-reader test in tests/hooks/guard-check.test.ts at guard-check.js as well — today it only spawns pre-edit-recall.js.

  2. kevintseng commented on Dec 2, 2026

    @kevintseng
    CollaboratorAuthor

    A matched guard now survives recall faults, and warning output is preserved on a slow pipe. Verified on the open PR #650.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions