Skip to content

feat: never auto-answer human-gate questions; reject human-gated agents - #2

Merged
jflowers merged 3 commits into
mainfrom
feat/human-gates
Nov 13, 2026
Merged

jflowers merged 3 commits into
mainfrom
feat/human-gates

Conversation

@jflowers

@jflowers jflowers commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Closes #1. Part of unbound-force/dewey#153.

What

  • HUMAN_GATE: marker. A question, or its header, that begins with HUMAN_GATE: always goes to the human, whatever the engine's confidence.
  • humanGatedAgents config key (default ["curator"]).
    • Config load fails when agents overlaps this list, with an error that names the agent and says to remove it.
    • Configured entries add to the built-in curator; they can't remove it.
    • As a backstop, the runtime also refuses a question from a gated session agent.
  • Ordering. Both checks run before pass 0, so project guidance documents can't override them.
  • Session summary. When enabled, a deferral leaves a summary line in the session saying why.
  • Logging. Config load failures (which leave the plugin inert) now log at error instead of warn.

Compatibility

  • The current ~/.config/opencode/auto-question.jsonc and the shipped template both still load.
  • Dewey's dewey gate auto-answer reads only the agents key, so the new key doesn't affect it.

Tests and CI

  • New CI: .github/workflows/ci.yml runs bun run typecheck and bun test --coverage (bun 1.4.4) on pull requests and on pushes to main. bun.lock is gitignored, so install resolves from the package.json ranges.
  • Totals: 103 tests, all passing. Line coverage is up from 57% to 84%, and orchestrator.ts from 51% to 91%.
  • src/test-harness.ts: a fake opencode HTTP client (question replies, session summaries, child sessions for subagents, session messages) plus a stubbed LLM engine, for end-to-end tests through handleQuestionAsked.
  • src/gate.test.ts: marker detection, config load (overlap, case-insensitive matching, the built-in list can only be extended, invalid type), and end to end with an engine that always returns 0.99 confidence:
    • An unmarked question is answered (the control case).
    • A marked question gets no engine call and no reply.
    • One marked question defers a whole multi-question v2 request.
    • Pass 0 never starts for a marked question, even with guidance telling it to answer. A control case shows pass 0 does start for an unmarked one.
    • A gated agent is refused at runtime.
    • With session summaries off, nothing is posted.
  • Fixed a test that couldn't fail: the first version of the pass-0 test counted client.session.create, which subagents never call. It now counts the real child sessions.
  • Mutation check: removing the gate check from handleQuestionAsked fails all 5 behavioural gate tests.
  • src/orchestrator.flow.test.ts (new, covering existing behaviour):
    • Pass 0: answered, covered but unconfident (defers), not covered (falls through), agent failure, and guidance disabled.
    • Pass 1 and pass 2 thresholds, including the case where no context is gathered.
    • A failed pass 2 keeps pass 1's decision; an engine error defers with that error as the reason.
    • Immediate context reaches the engine.
    • Handler timeout defers to the human.
    • v2 reply endpoint; settled requests and sessions with an unknown or non-autonomous agent are skipped; sessionSummary: false.

🤖 Generated with Claude Code

jflowers and others added 2 commits November 12, 2026 12:12
Questions beginning with the HUMAN_GATE: marker (the contract defined by
unbound-force/dewey's curator-agent-human-gates change, design D7) always
go to the human, regardless of engine confidence. Detection is lenient
(leading whitespace, any case, header too) because a false or spoofed
marker can only force a human answer. One marked question defers the
whole request.

A new humanGatedAgents config key (built-in "curator" always included)
makes config load fail with an actionable error when "agents" overlaps
it; a gated session agent is also refused at runtime as defense in
depth. Both checks run before pass 0, so project guidance cannot
override them. Config load failures now log at error level.

Closes #1

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- .github/workflows/ci.yml: bun 1.4.4, typecheck, bun test --coverage on
  pull requests and pushes to main.
- src/test-harness.ts: fake opencode HTTP client (replies, summaries,
  child sessions) plus a stubbed LLM engine for end-to-end tests.
- gate tests: the pass-0 assertion counted client.session.create, which
  subagents never call, so it could not fail; it now counts real child
  sessions, with a control case proving pass 0 runs when unmarked.
- orchestrator flow tests: pass 0/1/2, thresholds, engine errors,
  immediate context, handler timeout, settled and non-autonomous
  sessions. Coverage 57% -> 84% lines (orchestrator 51% -> 91%).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jflowers
jflowers marked this pull request as ready for review November 13, 2026 14:36
- Detect HUMAN_GATE markers a model may decorate or respell: leading
  markdown (**, _, `, >, #, -, list numbers), zero-width chars,
  HUMAN GATE / HUMAN-GATE spellings, emphasis before the colon. A marker
  mentioned mid-sentence still does not gate.
- A gated agent listed in `agents` is dropped with a logged error
  instead of failing the whole config load, which left every other
  agent's questions unanswered (a fleet-wide stall for unattended runs).
- Gated requests are settled atomically, so a repeat delivery
  (question.asked plus question.v2.asked, or a replay) no longer posts
  a duplicate "Deferred to human" summary. Shared markSettled helper.
- humanGatedAgents are deduplicated case-insensitively.
- Document that a false marker stalls unattended runs.
- Commit bun.lock and install with --frozen-lockfile in CI.
- Test harness installs its fetch stub only after setup succeeds and
  removes its temp dir if setup throws.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jflowers
jflowers merged commit 06f4f24 into main Nov 13, 2026
1 check 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.

feat: never auto-answer human-gate questions; reject human-gated agents in config

1 participant