Skip to content

fix(openfactor): skip tool hooks when no orchestration daemon listens - #3068

Merged
shunkakinoki merged 2 commits into
mainfrom
fix/openfactor-hook-socket-gate
Oct 14, 2026
Merged

shunkakinoki merged 2 commits into
mainfrom
fix/openfactor-hook-socket-gate

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • After openfactor hooks install, activation reads each host receipt's configPath. In each JSON hook config it wraps every non-prompt openfactor <harness>-hook <Event> command as sh -c 'test -S "<daemon socket>" || exit 0; exec openfactor ...'.
  • The generated OpenCode plugin gets the same existsSync(<daemon socket>) check before it spawns the CLI.
  • The socket path matches the CLI's own: ${OPENFACTOR_ORCHESTRATION_SOCKET:-${OPENFACTOR_ORCHESTRATION_STATE:-.orchestration-state}/daemon.sock}.

Why

On matic each PreToolUse/PostToolUse hook started the ~90 MB Bun CLI. Each start cost 0.67-0.75 s of user CPU and 0.37-0.42 s of wall time, and spiked to about 196% CPU per call across parallel tool calls. No orchestration daemon socket exists on the host, so the CLI posts nothing and exits. That was pure overhead on every tool call from every harness.

decided: gate in the activation wrapper rather than drop the hooks - lanes that run the daemon still get every event
decided: leave prompt events ungated - the CLI records lane prompt receipts from them without a daemon
decided: keep openfactor in the gated command string - hooks install treats an entry naming openfactor as installed, so re-runs stay idempotent instead of appending a second hook

Test plan

  • shellspec spec/openfactor_spec.sh (11 examples): gates tool hooks, leaves prompt and foreign hooks unchanged, re-run is idempotent, CLI runs only when the socket exists, OpenCode plugin is gated
  • shellcheck on install.sh and the spec
  • nixfmt --check config/openfactor/default.nix

🤖 Generated with Claude Code


Summary by cubic

Tool hooks installed by openfactor hooks install now check for the orchestration daemon socket before invoking the CLI, so tool calls outside orchestrated lanes no longer boot the ~90 MB Bun CLI just to drop the event—each start cost about 0.7 CPU-seconds per call.

  • Wraps every non-prompt openfactor <harness>-hook <Event> command in sh -c 'test -S "<daemon socket>" || exit 0; exec openfactor ...'; prompt hooks stay ungated because the CLI records lane prompt receipts without a daemon.
  • The generated OpenCode plugin gets the same existsSync gate before spawning the CLI.
  • The gated command keeps openfactor in its name, so re-running hooks install stays idempotent instead of appending a second hook.
  • config/openfactor/default.nix adds pkgs.jq, used by activation to read each host receipt's configPath.

Written for commit 7a8cf5d. Summary will update on new commits.

View guided diff Turn on auto-fix

Every harness tool call started the ~90 MB Bun OpenFactor CLI, about
0.7 CPU-seconds each, only for the CLI to find no daemon socket and drop
the event. Activation now wraps the non-prompt host hooks in a
`test -S <daemon socket>` check and gives the OpenCode plugin the same
check, so tool hooks cost one shell builtin outside orchestrated lanes.
Prompt hooks stay ungated because the CLI records lane prompt receipts
from them without a daemon.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@indent

indent Bot commented Oct 14, 2026

Copy link
Copy Markdown

Warning

This organization's free trial has ended, so Indent couldn't start this review. Manage billing to resume reviews on this repository.

Review agents

Select any unchecked box below to run or rerun that agent.

Pending (1)
  • Indent Review Agent · This agent has not run.
Full results

Indent Review Agent

  • Summary: This agent has not run.
  • Latest resultNo result — this agent has not run.

@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0b30e89d-7170-4ee2-9042-15e94483a8a9
📥 Commits

Reviewing files that changed from the base of the PR and between e1171bb and 7a8cf5d.

📒 Files selected for processing: 3
  • config/openfactor/default.nix
  • config/openfactor/install.sh
  • spec/openfactor_spec.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The PR correctly implements the fix to skip tool hooks when no orchestration daemon listens. The changes are:

  1. config/openfactor/default.nix - Added pkgs.jq to the package list (line 12)
  2. config/openfactor/install.sh - Added a socket gate that checks for the orchestration daemon socket before booting the ~90MB Bun CLI (lines 26-77). The CLI now only starts when the daemon socket exists, eliminating the ~0.7s CPU overhead per hook call.
  3. spec/openfactor_spec.sh - Updated the expected plugin content to include existsSync import (lines 132-136)

This optimizes performance by preventing unnecessary CLI launches when no orchestration daemon is listening. The gating ensures that tool hooks only run when the daemon is active, while prompt events remain ungated since they don't require a daemon. The changes are idempotent and maintain backward compatibility.

Pullfrog  | Fix it ➔ | View workflow run | Using free | 𝕏

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread config/openfactor/install.sh Resolved

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

The openfactor socket-gate fix (commit 497958b) was already reviewed and approved by Pullfrog. Since that review, only a merge of origin/main (commit 7a8cf5d) has landed on the branch. The merge brings in unrelated t3-connect browser-setup changes and coverage-spec updates — none of which touch the openfactor logic.

Reviewed changes

  • OpenFactor socket gate (config/openfactor/install.sh:51-77, config/openfactor/default.nix:12, spec/openfactor_spec.sh:131-186): Wraps non-prompt openfactor <harness>-hook <Event> commands in a test -S "<daemon socket>" || exit 0 guard so tool-call hooks skip the ~90 MB Bun CLI boot when no orchestration daemon is listening. Prompt hooks remain ungated. The OpenCode plugin receives an equivalent existsSync check. Idempotency is preserved by keeping openfactor in the gated command string. Comprehensive shellspec tests cover gating, prompt preservation, idempotency, and CLI execution only when the daemon socket exists.
  • Merge of origin/main (home-manager/services/t3-connect/setup-browser.sh, spec/coverage_spec.sh, spec/t3_browser_setup_spec.sh): Adds a defensive check for the T3 CLI browser subcommand before running browser setup, with corresponding test coverage. No impact on the openfactor changes.

Pullfrog  | View workflow run | Using free | 𝕏

@shunkakinoki
shunkakinoki merged commit 9368254 into main Oct 14, 2026
38 checks passed
@shunkakinoki
shunkakinoki deleted the fix/openfactor-hook-socket-gate branch October 14, 2026 10:38
@linear-code

linear-code Bot commented Oct 14, 2026

Copy link
Copy Markdown

SHUN-16628

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