DeepSeek-Reasonix icon indicating copy to clipboard operation
DeepSeek-Reasonix copied to clipboard

feat(intent): resolve delivery intent from tiered signals instead of keyword tables / 用分层信号替代关键词表解析交付意图

Open SivanCola opened this issue 3 months ago • 0 comments

Why

internal/taskintent isolates the keyword tables, but the tables themselves still decide what the delivery gates expect by substring-matching the user's prose. That approach has limits this repository already documents: five separate mutation-verb lists that its own comments warn must not drift apart, two different negation word lists that can judge one sentence oppositely, and Chinese matched by strings.Contains while English is matched by token — so "更新" hits "更新日志".

This PR adds the replacement mechanism and measures it, without changing any behavior yet. The keyword path still drives every gate; the new resolver runs alongside it and reports where they differ.

What

One shared reading, internal/intent.TurnIntent. Kind carries the coarse classification; FaultReport, ReadOnlyConstraint, DiagnosticIntent and DurableScope carry the orthogonal facts consumers need in order to disagree about the same turn. Derivations (NeedsEvidence, NeedsMutation, NeedsGoalWriteBudget, IsTask) stay deterministic Go next to the fields they read, so only perception could ever move to a model.

Kind alone would be lossy. The corpus pins a bare fault report that must start a Goal on the write budget while ordinary Delivery must not treat it as a mutation request — one sentence, opposite answers for two consumers. A flat boolean classifier cannot express that.

Three tiers, cheapest first.

Tier Source Cost
1 Host state — plan mode is a planning turn by decree, not inference free
2 The model's own declarations — writing todos or acceptance criteria is it stating in a typed channel that this turn is a task free
3 An injected classifier, consulted only when the first two stay silent one small model call

The resolver runs at gate time, not turn start: beginRunTurn resets the evidence ledger before classifying, so the declared tier has nothing to read until the turn has produced receipts.

Tier 3 is launched concurrently with the turn, not called at the gate. A classifier measured at ~3.8s would be that much added latency at the moment the model wants to finish; overlapped with the turn's own round-trips it is effectively free. The cost is that a turn later answered by tier 2 still paid for a classification it did not use.

One corpus. The three golden tables that judge this behavior each carried their own inline copy. They now read from internal/intent/corpus — 123 cases, 185 labels — so the gate tests and the accuracy harness judge the same corpus. Duplicating the corpus that judges drifting tables would reproduce the defect one level up. The transcription was verified mechanically against the original tables, label by label, before the tests were changed.

Measured

Live evaluation against the corpus, via a harness that skips without credentials so CI stays hermetic and free:

  • 99.5% median across five runs (98.4 / 100 / 99.5 / 99.5 / 99.5), 3.79s mean latency.
  • Prompt iteration mattered far more than model choice: 94.4% → 99.5% by stating product rules the model cannot infer; a more accurate model bought 0.4% for double the latency.
  • Most initial misses were unstated rules, not model incapacity. Six of the first nine disagreements were one missing rule each.
  • DiagnosticIntent exists because live evaluation proved ReadOnlyConstraint could not express "diagnose without forbidding anything".
  • The classifier is not deterministic at temperature=0: correct labels ranged 182–185 of 185 across identical runs. A word table does not do that. For a gate that can block a user, this is a property to accept knowingly, not a bug to fix.

Real delivery-profile traffic (six turns) splits roughly evenly between tier 2 and tier 3, and the pattern is the opposite of the intuitive one: turns doing real work resolve free at tier 2 because the model writes todos, while chat, advisory and simple reads fall through to the paid classifier — the turns where an extra model call is proportionally most wasteful.

Two defects the shadow found

  1. The production classifier lacked the empty-reply retry that the evaluation harness had. Reasoning models intermittently return empty content with the budget spent in reasoning_content, measured at roughly 3% of calls. The harness reported zero errors because it retried; production would have absorbed the full rate silently. Both now share one sentinel.

  2. Tier 2's mutation inference was unsound. An earlier version inferred KindMutation from an unfinished todo list plus writer tools. Real traffic disproved it on 帮我看下 main.go 有没有问题,只分析不要改, where the model wrote todos for an explicitly read-only analysis and the inference armed a mutation expectation the user had forbidden. An unfinished todo list proves the model thinks the work is incomplete — not that a state change was requested. Removed.

Known gap

Removing that inference leaves tier 2 able to establish that a turn is a task but never that it requires a mutation, and it stops the cascade before tier 3 could answer. The cause is that the tiers answer different questions: Task is provable from the model's behavior, Mutation is only knowable from what the user asked. Resolving it needs per-field tier composition rather than one winning tier. That is a separate change; this PR does not attempt it.

Not touched

Keyword matching over shell commands and tool arguments — internal/recovery/rules.go, internal/permission/bash_approval.go, internal/shellsafe — is deliberately left alone. Those classify machine-generated artifacts for a security boundary, not user prose. A model-based security boundary would be non-deterministic, promptable from the same context that carries the user's text, and would fail open when the provider is down. Explicit syntax (/cmd, @file, # note) is likewise parsing, not inference, and stays.

Enabling

Off by default — nil classifier, no cost, no behavior change:

[agent.subagent_models]
intent-classifier = "<provider>/<small-model>"

REASONIX_INTENT_SHADOW=1 prints the tier distribution and keyword agreement to stderr at session end. Opt-in, stderr only, no persisted format.

Verification

  • TestLegacyDeliveryExpectationsMatchesHistoricalExpression asserts the routed legacy path equals the pre-contract expression byte-for-byte across all 123 corpus turns under both writer-tool states.
  • Tier precedence, degradation (KindUnknown must never read as KindConversation), bounded await, per-turn future isolation and repeatable resolution are pinned separately.
  • go build ./..., go vet, gofmt clean; every commit builds and passes its tests independently.
  • go test -race on the owning packages: no data race, no goroutine leak. The race detector caught one real defect during development — the classification goroutine dereferenced an Agent field instead of capturing it — which is fixed.
  • Two failures on this machine (TestMissingReasoningWarnStateReadFailureDoesNotOverwriteExistingIncidents, TestMiddleClickUsesPrimarySelectionOutsideTmux) reproduce identically on the base commit with no changes applied; both are environmental (running as root ignores the chmod the first one simulates; the second needs an X11 primary selection).

Cache

No change to prompt construction, system prefix, tool schemas, or provider serialization. Resolution happens host-side from existing turn text and evidence receipts. Tier 3 is an independent small-model call that does not share or pollute the main conversation prefix.

SivanCola avatar Aug 07 '26 01:08 SivanCola