Skip to content

Keep AI Micro bridge running independently of App sessions - #3

Merged
user3301 merged 4 commits into
mainfrom
feat-independent-bridge
Oct 5, 2026
Merged

user3301 merged 4 commits into
mainfrom
feat-independent-bridge

Conversation

@user3301

@user3301 user3301 commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Move HID ownership, device reconnection, configuration and URI navigation into a separately launched Windows daemon so recycling the hosting CLI disconnects only the App status feed.
  • Connect the extension through authenticated, bounded Windows named-pipe request/reply transport with a per-user singleton service and one status producer.
  • Keep Agent-key, previous/next and focus navigation working from verified cached App URLs while offline. Mark LEDs unknown on feed loss or expiry; require fresh App data for waiting-session actions, session creation and configuration changes.
  • Automatically restore status publishing when the extension loads again without reopening HID. Explicit stop remains stopped after feed recovery.
  • Document startup, shutdown, local configuration, runtime credentials and limitations; ignore runtime credential files.

Validation

  • Windows npm test: 56 tests passed, no failures or skips.
  • npm run check: passed.
  • Unstaged and staged git -c core.whitespace=cr-at-eol diff --check: passed.
  • Real separate Node-process and Windows named-pipe tests cover producer termination, cached navigation, unknown LEDs, status recovery, explicit stop, feed expiry, invalid catalogue rejection and authentication.
  • Existing bounded-output and real PowerShell URL-validation regressions remain passing.
  • The active hardware bridge was not restarted and extensions were not reloaded during submission.

Operational notes

  • Run npm run daemon in an independent terminal or explicitly detached process, then configure and start through the extension. No Windows autostart is installed; computer restart or daemon exit still requires service startup and explicit bridge start.
  • Keep or migrate personal config.json locally in the hosting extension directory. It is not distributed through Git. Never copy or share .bridge-runtime.json.
  • Cached targets may have been deleted; URLs are validated and never substituted. Navigation does not guarantee immediate loading of the App status extension.
  • Sleep/wake, Bluetooth-adapter toggling and long-running hardware stability still need separate validation. Forced daemon termination can leave the last hardware LED colors visible.
  • No firmware changes, automatic approvals or agent prompt sending.

Only source, tests and documentation are included. Personal configuration, device/session bindings, dependencies and runtime credentials are excluded.

Separate HID lifetime from the session status feed with an authenticated local daemon, cached navigation and automatic feed recovery.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Large valid App catalogues can exceed the RPC frame limit and disconnect the status feed.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Introduces an independent Windows daemon so HID ownership and cached navigation survive App session recycling.

Changes:

  • Adds authenticated named-pipe RPC between the extension and daemon.
  • Preserves cached navigation while marking stale status unknown.
  • Adds Windows lifecycle tests and updated operational documentation.
File Description
README.md Documents the independent daemon workflow.
.github/​extensions/​ai-micro-copilot/​README.md Updates detailed setup and lifecycle guidance.
.github/​extensions/​ai-micro-copilot/​package.json Adds daemon and syntax-check scripts.
.github/​extensions/​ai-micro-copilot/​.gitignore Excludes runtime credential files.
.github/​extensions/​ai-micro-copilot/​extension.mjs Delegates bridge operations to the daemon client.
.github/​extensions/​ai-micro-copilot/​daemon.mjs Implements the standalone daemon entrypoint.
.github/​extensions/​ai-micro-copilot/​bridge-client.mjs Publishes App state over RPC.
.github/​extensions/​ai-micro-copilot/​bridge-service.mjs Owns HID, configuration, and cached navigation.
.github/​extensions/​ai-micro-copilot/​bridge-rpc.mjs Implements authenticated bounded RPC.
.github/​extensions/​ai-micro-copilot/​controller.mjs Enables cached navigation during feed loss.
.github/​extensions/​ai-micro-copilot/​tests/​persistent.test.mjs Tests daemon persistence and recovery.
.github/​extensions/​ai-micro-copilot/​tests/​bridge-client.test.mjs Tests extension reconnection behavior.
.github/​extensions/​ai-micro-copilot/​tests/​fixtures/​persistent-worker.mjs Provides the daemon test fixture.
.github/​extensions/​ai-micro-copilot/​tests/​fixtures/​feed-worker.mjs Provides the status-feed test fixture.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .github/extensions/ai-micro-copilot/bridge-client.mjs Outdated
Keep the 1 MiB RPC guard while allowing large App catalogues, new bindings and regular status updates. Add a real named-pipe regression with over 12000 sessions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Daemon shutdown can race a concurrent start request and leave HID reopened as the process exits.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Comment thread .github/extensions/ai-micro-copilot/bridge-service.mjs Outdated
Seal pipe admission and close clients before draining controls and stopping HID. Cover late starts, in-flight starts and concurrent shutdown with real named-pipe regressions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Shutdown ownership races and blocking or premature timeout paths can leave daemon state inconsistent or management controls unavailable.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Unbounded feed polling blocks status and stop requests

.github/​extensions/​ai-micro-copilot/​bridge-client.mjs:99

The background poll runs publish() inside the same serialization queue as every tool request. readSessions()/callApp() have no deadline, so a stalled App status call permanently holds this queue; subsequent status and explicit stop requests never reach the still-responsive daemon. This defeats the feed-expiry path precisely when it is needed. Keep feed polling from blocking management controls, or bound/cancel the App calls so the queue is always released.

Medium severity RPC deadline is shorter than the valid start sequence

.github/​extensions/​ai-micro-copilot/​bridge-rpc.mjs:51

The default RPC deadline is shorter than a valid start sequence: URI-helper startup may take almost 10 seconds, followed by four sequential firmware requests that may each succeed just under their 3-second deadline. The client can therefore close the peer at 15 seconds while the service continues and ultimately starts HID, reporting failure even though the bridge is running. Give start a deadline longer than its composed sub-operation limits, or propagate timeout cancellation to the server operation.

Comment thread .github/extensions/ai-micro-copilot/bridge-service.mjs
Keep rejecting traffic while draining HID and removing discovery, then release the named pipe. Verify blocked replacement claims and safe runtime handoff with real Windows pipes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

The Windows credential file lacks enforced owner-only access, and valid coalesced RPC frames can be rejected incorrectly.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Rejecting valid frames due to aggregate buffer size

.github/​extensions/​ai-micro-copilot/​bridge-rpc.mjs:39

The size check runs before newline-delimited frames are consumed, so a valid near-limit frame followed by part of another frame makes the aggregate buffer exceed 1 MiB and closes the connection even though neither frame exceeds the documented limit. Apply the limit to each complete line, then separately reject only an oversized unterminated remainder; add a regression with split/coalesced frames.

Comment on lines +45 to +48
await writeFile(`${runtimePath}.tmp`, JSON.stringify({
protocol: 1, endpoint, token, pid: process.pid, configPath,
}) + "\n", { mode: 0o600 });
await rename(`${runtimePath}.tmp`, runtimePath);
@user3301
user3301 merged commit 8085c60 into main Oct 5, 2026
3 checks passed
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.

2 participants