Skip to content

fix(hive): preserve Pi tool identity across hook events - #511

Open
HsienW wants to merge 1 commit into
chaitanyagiri:mainfrom
HsienW:fix/pi-tool-event-normalization
Open

HsienW wants to merge 1 commit into
chaitanyagiri:mainfrom
HsienW:fix/pi-tool-event-normalization

Conversation

@HsienW

@HsienW HsienW commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

What & why

  • Pi's live tool_call and tool_result events expose tool identity through toolName and input, while the generated Pi bridge was still reading the earlier name / tool.name / args shapes. PostToolUse also dropped the input entirely, which could collapse different tool calls into the same CircuitBreaker fingerprint and incorrectly constrain a healthy agent.

  • This follows the direction validated in the issue: preserve Pi's confirmed toolName and input on both tool boundaries. The bridge now prefers those confirmed fields while keeping the existing legacy fallbacks, and both PreToolUse and PostToolUse share the same Pi-local normalization path.

  • The change stays scoped to the generated Pi bridge. It does not change CircuitBreaker fingerprinting, HookServer behavior, or any other provider bridge.

Closes #502.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Docs
  • Build / CI

Evidence

Before

Current main, running the new Pi bridge regression against the unrepaired generated bridge:

  • confirmed Pi toolName / input mapping fails
  • distinct Pi calls collapse through the real breaker path
  • 2 tests pass, 9 fail
2026-09-14-123616

After

The same regression on this branch:

  • confirmed Pi fields are preserved on both tool boundaries
  • legacy name, tool.name, and args fallbacks remain supported
  • defined falsy inputs such as '', false, and 0 are preserved
  • JSON-like text, Windows paths, CR/LF, and escaping round-trip without parsing inner input
  • transport, serialization, approval callback, and registration failures remain fail-open
  • 13 distinct Pi calls stay healthy through the real CircuitBreaker
  • 8 genuinely identical Pi calls still reach constrained
  • 11 tests pass, 0 fail
2026-09-13-230924

How I tested it

  • OS: Windows 11
  • Node.js: v22.22.3
  • Steps:
node --test .\test\pi-bridge.test.cjs

Result:

tests 11
pass 11
fail 0

The focused Pi regression exercises the actual generated bridge through Node VM and a mocked socket, then feeds the resulting PostToolUse events through the real CircuitBreaker.

Existing CircuitBreaker coverage also passes:

CircuitBreaker suite: 35/35 passed

Additional validation:

npm run typecheck: PASS
git diff --check: PASS

I also ran:

npm run test:focused

The full focused suite is not completely green on my Windows environment. The remaining failures are in existing Windows-specific symlink permission, HOME/path resolution, and source assertion cases outside the files changed by this PR. The new Pi bridge regression passes in full.

Checklist

  • Before and after evidence is attached above, under both headings.
  • npm run typecheck passes.
  • npm run test:focused passes.
  • npm run build succeeds.
  • This PR is one change. Unrelated fixes belong in their own PR.
  • I read the diff myself before opening this, and there is no debug output, commented-out code, or unrelated formatting churn in it.
  • Any new UI derives from DESIGN.md / tokens.ts because this PR adds no UI.
  • If I added art, it's my own or compatibly licensed, and listed in ATTRIBUTION.md because this PR adds no art.

- prefer Pi's confirmed toolName and input fields while retaining legacy fallbacks

- normalize PreToolUse and PostToolUse through the same bridge mapping

- keep malformed and unserializable inputs fail-open without collapsing fingerprints

- add Pi bridge regressions for event mapping, socket failures, and breaker behavior
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.

Pi bridge drops tool name/input, causing false circuit-breaker constraints

1 participant