Skip to content

perf(context-guard): log path and duration for every zone-crossing-inject fire - #5667

Merged
kyle-sexton merged 6 commits into
mainfrom
perf/5298-zone-crossing-fire-telemetry
Oct 1, 2026
Merged

kyle-sexton merged 6 commits into
mainfrom
perf/5298-zone-crossing-fire-telemetry

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Refs: #5298

Summary

zone-crossing-inject ran on every PostToolBatch and UserPromptSubmit but recorded telemetry only on a zone transition, so there was no way to see what share of fires pay for the resolver. Every fire that reaches a zone decision now writes one record carrying path (fast, coalesced or resolving) beside the envelope duration. With no sink configured nothing extra is sourced or run.

Fix

  • The hook records path on each fire, and on the existing transition and error records.
  • context-guard 0.7.95, with a CHANGELOG entry.
  • data/zone-crossing-inject.schema.json documents path and the per-fire emission.

Verification

Related

#5298

🤖 Generated with Claude Code

kyle-sexton and others added 5 commits October 1, 2026 09:14
…e with its path

Every fire that reaches a zone decision now writes one record whose data
carries path fast, coalesced or resolving, and the existing error, zone
change and injection records gain the same field instead of a second
record. With no sink configured nothing extra is sourced or run.

Refs: #5298

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mented

Bumps context-guard to 0.7.95, adds the changelog entry and documents the
path field and the one-record-per-fire emission in the telemetry schema.

Refs: #5298

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cord

The CHANGELOG, the telemetry schema and the hook header said coalesced
means a snapshot that only moved captured_at. cg_try_coalesce also
succeeds when no zones.json exists and only used_percentage moved within
one shipped band, so the share would have counted percentage-band hits as
captured_at-only hits. The comment above the no-worse-zone exit still said
an unchanged zone is not an event, but that case now records path and zone.

Refs: #5298

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review October 1, 2026 13:32
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T13:36:22.513606Z fd52ebc 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.

@claude

claude Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in progress

  • Gather context (PR diff, changed files)
  • Understand the request (run /review:code-review per instructions)
  • Review changed files for correctness/maintainability
  • Post findings

View job run

@claude

claude Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 8s —— View job


Security review complete

  • Gather context (PR diff, changed files)
  • Review zone-crossing-inject.sh changes for injection / trust-boundary issues
  • Review schema and test changes
  • Check for instruction-surface deletions (CLAUDE.md/AGENTS.md/rules)
  • Post findings

No security issues found.

This PR is telemetry-only and introduces no new trust boundary:

  • CG_PATH (zone-crossing-inject.sh#L187-L199) is only ever assigned one of three hardcoded literals (fast, coalesced, resolving) inside the script itself — never derived from session input, file contents, or any attacker-influenced value — so interpolating it into the JSON data payloads (e.g. L928-L933) carries no injection surface.
  • The pre-existing $zone string interpolation into JSON literals (e.g. L753-L756) and the HOOK_TELEMETRY_SINK execution mechanism in hook-utils.sh are untouched by this diff, so they're out of scope for this review per the high-signal bar (pre-existing issues excluded).
  • cg_fire_telemetry (L187-L199) correctly gates on HOOK_TELEMETRY_SINK being set before loading utils or emitting anything, matching the PR's claim that "with no sink configured nothing extra is sourced or run" — verified this holds (test case "with no sink a fast fire writes nothing and sources no hook-utils").
  • Schema, CHANGELOG, and plugin-version changes are documentation/metadata only.
  • No CLAUDE.md/AGENTS.md/rules/skill files are touched, so the instruction-surface-deletion check doesn't apply here.

@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: fd52ebcae7

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

… early-exit fires

Pre-0.7.96 records have no path and a later execution path would fail a closed
enum, so the schema now leaves path optional and lists its known values in the
description. A fire that exits on missing jq or an unusable state directory
after its zone is decided now records an error with a reason.

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

claude Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 2m 10s —— View job


Security review complete

  • Gather context (PR diff, changed files)
  • Review zone-crossing-inject.sh changes for injection / trust-boundary issues
  • Review schema and test changes
  • Check for instruction-surface deletions (CLAUDE.md/AGENTS.md/rules)
  • Post findings

No security issues found.

This is a re-review of the current head (ccd61f6) against /review:security-review criteria. The PR remains telemetry-only with no new trust boundary:

  • CG_PATH (zone-crossing-inject.sh#L193, set at L733/L735) is still only ever one of the three hardcoded literals fast/coalesced/resolving, assigned inside the script itself, never from session input or file contents — so every new interpolation site (e.g. L860, L864, L903, L942) carries no injection surface.
  • $zone at the new jq_missing/state_dir_unavailable emit sites (L860, L864) is reached only after the smart|acceptable|dumb gate at L753, so it is constrained to those three literals there too.
  • The pre-existing $zone/$last/$armed/$persist_failed string interpolation into JSON literals (e.g. L902-L903) and the HOOK_TELEMETRY_SINK execution mechanism in hook-utils.sh are untouched by this diff's logic (only a hardcoded ,"path":"..." field was appended to each), so they stay out of scope per the high-signal bar.
  • cg_fire_telemetry (L194-L198) still gates on HOOK_TELEMETRY_SINK before loading utils or emitting anything.
  • Schema, CHANGELOG, and plugin-version changes are documentation/metadata only; the two Codex P2 schema comments (making path optional and leaving it an open string rather than a closed enum) are both resolved in the current schema.
  • The third Codex comment (emit telemetry on the post-decision jq-missing / state-dir-unavailable exits) is also addressed: both arms now call cg_fire_telemetry error ... with a reason before exiting (L859-L866).
  • No CLAUDE.md/AGENTS.md/rules/skill files are touched, so the instruction-surface-deletion check doesn't apply here.

@claude

claude Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 3m 56s —— View job


Code review (/review:code-review)

  • Gather context (PR diff, changed files)
  • Run /review:code-review criteria against the diff
  • Review changed files for correctness/maintainability
  • Post findings

No new findings.

I reviewed the current head (ccd61f6) against origin/main — docs/conventions/hook-telemetry/data/zone-crossing-inject.schema.json, plugins/context-guard/hooks/zone-crossing-inject.sh, zone-crossing-inject.test.sh, CHANGELOG.md, and plugin.json.

The three P2 findings from Codex's earlier pass on fd52ebc are addressed in ccd61f6:

I traced every exit path in the rewritten hook body (fast-skip, coalesce, resolve, unknown, jq-missing, state-dir-unavailable, persist-failed, suppressed-transition, injected) and each one emits cg_fire_telemetry/hook::emit_telemetry exactly once with a path consistent with how that fire actually reached its decision — no double-emits, no silently-dropped fires past the "reaches a zone decision" point. cg_fire_telemetry correctly short-circuits on an unset HOOK_TELEMETRY_SINK before sourcing anything, and the two new error paths build their JSON through hook::emit_telemetry's builtin compactor, so they don't depend on the very jq whose absence they're reporting. Schema, CHANGELOG, and plugin version bump (0.7.95 → 0.7.96) are consistent with the implementation.

I was not able to execute bash plugins/context-guard/hooks/zone-crossing-inject.test.sh myself in this environment (command execution was denied), so the PASS=192/FAIL=0 result in the PR description is author-claimed and unverified by me; my review above is based on static reading of the diff and the full hook/test file.

@kyle-sexton
kyle-sexton merged commit 0ce7b94 into main Oct 1, 2026
3 checks passed
@kyle-sexton
kyle-sexton deleted the perf/5298-zone-crossing-fire-telemetry branch October 1, 2026 14:01
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