Skip to content

fix(broker): a park-path refusal keeps its own code, and hosted becomes hostedTurn - #2010

Merged
lilyshen0722 merged 1 commit into
mainfrom
kai/task172-broker-refusal-code
Sep 29, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
kai/task172-broker-refusal-code

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes the two follow-ups recorded on TASK-172's row in slice 3c-2 (PR #2005, merged). Both are in the same call path; neither changes behaviour beyond what is named. Backend-only, so no version bump.

1. A park-path refusal keeps its own code

callTool's park path wrapped resolveApprovalPodId and proposeAction in one catch {} and threw approval_unavailable (503) for every cause. But resolveApprovalPodId refuses:

  • connection_mismatch — "grant connection owner is missing" (:781), and
  • invalid_target — a malformed grant target (:777),

both permanent 403s. Relabelled as a retryable 503, the agent is told to try again at something no retry can fix, and the ledger's reason column records a reason that is not the cause.

Now a cause that is already a RoomGrantError keeps its own code, message and status — recorded to the ledger under that code, still recorded: true so the outer catch does not double-record — and only an unclassified failure (the approval store unavailable) is approval_unavailable. The explicit { ok: false } branch below is untouched: a card that could not be built is genuinely approval_unavailable.

The one deviation, and its resolution. The remedy as first stated was safeReason(error) on this path; it is deliberately not implemented, and @vera withdrew it after measuring the schema (msg 75382): tool_calls.reason is VARCHAR(255) with no CHECK, so free text is accepted right up to 256 characters — where the INSERT throws 22001 inside the catch, replacing the original cause with a Postgres error. The proposed remedy could have destroyed the diagnostic it was meant to add. So the column stays a code column on a ground harder than taste: it is read by exact match (toolBrokerApprovalService.test.js:112), and the defect here was never that the ledger held a code — it held the wrong one.

2. hosted → hostedTurn

BrokerCallInput.hosted named a connection while answering a question about the turn: assertSeatCanConfine opens with if (input.hosted) return;. Read as a name, that says the bypass is a property of the provider (connectionType === 'hosted-mcp'), when it means the runtime is Commonly's own and has no shell to confine — a shelled seat calling a hosted tool must still be judged. Renamed hostedTurn; the type now names its single caller (grantBrokerProjectionService.dispatchHostedBrokerTool), and the four suites that pass the flag follow. AX audit entry 73.

Evidence

Two arms carry the change, and the positive control pre-existed:

arm asserts
toolBrokerService.hosted.test.js "refuses a hosted write whose row names no owner as a connection mismatch…" code: 'connection_mismatch', statusCode: 403 and ledger reason: 'connection_mismatch'; no room requested, nothing reaches the vendor
toolBrokerApprovalService.test.js "records a refusal when the approval proposal throws" (unchanged) a plain Error still yields approval_unavailable + reason: 'approval_unavailable'

Mutation ledger — 5 suites, baseline 67 tests, anchor occurrence count printed and asserted, pristine source restored and re-asserted after each arm (/tmp/kai-172b-ledger.py):

M01 blanket conversion restored      KILLED  hosted refusal arm red
M02 hosted-turn bypass deleted       KILLED  "a hosted turn is out of scope" red
M03 any error read for its code      KILLED  proposal-throws control red
M04 ledger reason back to generic    KILLED  hosted refusal arm red
4 mutations / 4 killed / 0 equivalent / 0 survivors / 0 compiler-refused -> ledger: OK

Full backend suite: 492 suites passed / 6 skipped; 4676 tests passed / 24 skipped / 0 failed. eslint on both changed services: 0 errors.

Gate: vera.

…omes `hostedTurn`

Two recorded follow-ups from TASK-172 slice 3c-2, in one diff because both are
in the same call path and neither changes behaviour beyond what is named.

1. The park path's catch relabelled every cause `approval_unavailable` (503).
   `resolveApprovalPodId` refuses `connection_mismatch` when a seat grant's
   connection names no owner, and `invalid_target` when the target is malformed
   — permanent 403s. Reporting them as a retryable 503 told the agent to retry
   something no retry can fix, and the ledger recorded a `reason` that was not
   the cause. A cause that is already a `RoomGrantError` now keeps its code,
   message and status; only an unclassified failure (the approval store being
   unavailable) stays `approval_unavailable`.

   Vera's remedy as stated — `safeReason(error)` on this path — is deliberately
   NOT implemented: `reason` is a code column with exact-match arms, so free
   text there is a format-or-schema decision that belongs with the first vendor
   entry, not here.

2. `BrokerCallInput.hosted` named a connection while answering a question about
   the turn, so the seat-confinement bypass read as a property of the provider —
   a shelled seat calling a hosted tool must still be judged. Renamed
   `hostedTurn`, with the type naming its single caller
   (`grantBrokerProjectionService.dispatchHostedBrokerTool`). AX audit entry 73.

Tests: the hosted arm that pinned the outcome (`approval_unavailable`) now pins
the cause (`connection_mismatch`, 403) and the ledger reason; the positive
control that a non-`RoomGrantError` cause still reports `approval_unavailable`
already existed in `toolBrokerApprovalService.test.js` and is unchanged.

Ledger (5 suites, baseline 67 tests, anchor count printed, source restored and
re-asserted per mutant): 4 mutations, 4 killed, 0 survivors.
  M01 blanket conversion restored      -> hosted refusal arm red
  M02 hosted-turn bypass deleted       -> "a hosted turn is out of scope" red
  M03 any error read for its code      -> proposal-throws control red
  M04 ledger reason back to generic    -> hosted refusal arm red

Full backend: 492 suites passed / 6 skipped; 4676 tests passed / 24 skipped /
0 failed. eslint on both changed services: 0 errors.
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Sep 29, 2026
Merged via the queue into main with commit 02773f6 Sep 29, 2026
23 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.

1 participant