Skip to content

Keep one list of Harbor's error codes, and make the docs match it - #133

Open
samuelcole wants to merge 7 commits into
mainfrom
sam/hbr-107-one-error-code-list
Open

samuelcole wants to merge 7 commits into
mainfrom
sam/hbr-107-one-error-code-list

Conversation

@samuelcole

@samuelcole samuelcole commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes HBR-107

Problem

Harbor kept two hand-maintained lists of error codes: the background's ApiErrorCode union and the page API's ErrorCodes. Both had drifted from what handlers send. Along the way:

  • An invocation that Harbor itself couldn't deliver came back with one of seven codes no doc described (ERR_NOT_ACCEPTED, ERR_NO_HANDLER, ERR_NO_TAB, ERR_SEND_FAILED, ERR_FORWARD_FAILED, ERR_INVOCATION_FAILED, ERR_FAILED).
  • The docs and the spec described codes Harbor never sends: ERR_USER_GESTURE_REQUIRED, ERR_SCOPE_REQUIRED, ERR_NOT_INSTALLED, ERR_TOOL_TIMEOUT, ERR_RATE_LIMITED, and several MCP and bridge codes. Example code in four docs handled ERR_SCOPE_REQUIRED, which can't happen.
  • The test harness's mock threw ERR_SCOPE_REQUIRED for a missing scope, so apps tested against it checked for a code Harbor never sends.
  • WebAgentError had no callers.

Change

  • One list. ErrorCodes in extension/src/page-api/types.ts is the only list, and ApiErrorCode is an alias of it. It holds exactly the codes the extension sends.

  • Overlapping invocation codes merged into the documented ones:

    • ERR_AGENT_NOT_ACCEPTING when the target doesn't accept invocations or has no handler.
    • ERR_AGENT_NOT_FOUND when its page can't be reached. That's what Harbor already sends when the page is gone.
    • ERR_INTERNAL when Harbor's own delivery throws. Deliberately not ERR_HANDLER_FAILED, which marks an answer as the agent's own and gives it provenance.

    The never-called reject callback that held ERR_FAILED is deleted.

  • Docs and spec match Harbor. docs/WEB_AGENTS_API.md now has the one complete table. The other docs keep short tables of the codes their surface returns, plus a link to it. spec/explainer.md and its mirror docs/HARBOR_WEB_API_EXPLAINER.md now list exactly Harbor's codes. The spec no longer promises a user-gesture check, and spec/security-privacy.md no longer shows a rate-limit step. Neither is enforced. The ERR_LABEL_FLOW_BLOCKED row was marked "reserved, not produced", but the policy engine does produce it, so the row now says what it means.

  • Harness mock throws ERR_PERMISSION_DENIED for a missing scope, as Harbor does when the person declines.

  • A test keeps it all in step. extension/src/page-api/__tests__/error-codes-list.test.ts fails in any of these cases:

    • the extension's source sends a code that isn't on the list;
    • a listed code is never sent;
    • the docs, spec or harness name a code Harbor doesn't have;
    • the full table leaves a code out.

Also fixed

  • The harness mock's missing-scope code (above). It's in the CHANGELOG.
  • ARCHITECTURE.md said the codes live in shared/protocol.ts, which doesn't exist.

Testing

  • Red first. The list test failed with 20 codes missing from the list. The new invocation tests failed because each path still sent its old code. The docs checks failed on 54 stale mentions.
  • npm test --prefix extension: 159 files, 1794 tests pass.
  • npm run build (Firefox) passes.
  • npx tsc --noEmit -p extension: 36 errors at base (aef1ea5) and at head, with identical lists.
  • The generated harness's example tests pass: 27 tests in a freshly generated harness.
  • New invocation tests cover not accepting, no handler, delivery throwing, send failure and no tab. Each one checks the code and that the answer has no provenance. Two of them run through the real page port listener.
  • Not tested in Firefox. These paths need a tab that disappears mid-send, or a handler that's missing, which a demo can't easily produce. The unit tests drive the background's real listeners instead.
  • Not covered by a test: the forwarder's ERR_INTERNAL catch in agents/handlers/multi-agent.ts. Only the list test reaches it. Also, docs/MCP_HOST.md's "server down returns ERR_TOOL_FAILED" matches the code, but no test exercises that case.

What's left

  • ERR_CHAT, ERR_CHAT_OPEN, ERR_CHAT_CLOSE and the three ERR_MCP_* codes stay as they are. They're documented and tested, and pages may rely on them.

Opened by Claude Code.

🤖 Generated with Claude Code

samuelcole and others added 7 commits November 25, 2026 17:26
The background's ApiErrorCode union and the page API's ErrorCodes were
separate hand-kept lists, and both had drifted from what handlers send.
ApiErrorCode is now derived from ErrorCodes, ErrorCodes gains the 20 codes
the extension emits that it was missing, and a test fails if the source
emits an ERR_* code that isn't on the list. No code a page sees changes.

Also delete WebAgentError, which nothing used.

Co-Authored-By: Claude Opus 5.5 (Claude Code) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (Claude Code) <noreply@anthropic.com>
An invocation Harbor couldn't deliver came back with one of seven
one-off codes. They now use the documented codes for what happened:

- ERR_AGENT_NOT_ACCEPTING when the target doesn't accept invocations or
  has no handler (was ERR_NOT_ACCEPTED or ERR_NO_HANDLER).
- ERR_AGENT_NOT_FOUND when the agent's page can't be reached (was
  ERR_NO_TAB or ERR_SEND_FAILED).
- ERR_INTERNAL when Harbor's own delivery throws (was ERR_FORWARD_FAILED
  or ERR_INVOCATION_FAILED).

ERR_FAILED sat in a callback nothing called; it's deleted with it.
ERR_NOT_INSTALLED, ERR_SCOPE_REQUIRED and ERR_TOOL_TIMEOUT leave the list
because nothing sends them. The test harness's mock threw
ERR_SCOPE_REQUIRED for a missing scope; it now throws
ERR_PERMISSION_DENIED, as Harbor does.

The list test now also fails on a listed code nothing sends, and on a
doc naming a code Harbor doesn't have. The docs still fail it; the next
commit fixes them.

Co-Authored-By: Claude Opus 5.5 (Claude Code) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (Claude Code) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 (Claude Code) <noreply@anthropic.com>
@samuelcole samuelcole changed the title Keep one list of Harbor's error codes Keep one list of Harbor's error codes, and make the docs match it Nov 27, 2026

This branch has not been deployed

No deployments
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