Skip to content

feat(dispatch-resolve): record each resolution in a JSONL decision log - #7365

Open
Azd325 wants to merge 10 commits into
kunchenguid:mainfrom
Azd325:fm/dispatch-resolve-decision-log
Open

Azd325 wants to merge 10 commits into
kunchenguid:mainfrom
Azd325:fm/dispatch-resolve-decision-log

Conversation

@Azd325

@Azd325 Azd325 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

  • bin/fm-dispatch-resolve.sh now appends one JSON line per resolution that reached the API (clear, ambiguous, escalate, or error after the request) to dispatch-resolve.jsonl. The file lives in FM_STATE_OVERRIDE, or else $FM_HOME/state. Each line holds the timestamp, task id, project, status, rule, a 60-character rule_when excerpt, confidence, probabilities, and the fallback rule when one was taken. For clear results it also holds profile_source (the rule or default that supplied the profile) and the chosen profile. It never holds brief text or the API key. The off path and usage errors write nothing. A failed write prints one stderr warning and leaves stdout and the exit code unchanged.
  • The resolver result now includes profile_source and fallback_rule. emit_error records the matched rule and its when text when the response was valid.
  • docs/configuration.md has a new "Resolution record" section. tests/fm-dispatch-resolve.test.sh has 120 added lines of tests for the record.

Risk Assessment

✅ Low: The log reuses the already-resolved TASK_ID, so both reported failures are fixed; the fix round only aligns the log path with FM_STATE_OVERRIDE, and log write failures do not change stdout or the exit code.

Testing

I ran the real bin/fm-dispatch-resolve.sh through its test file, against a stubbed model API and quota tool. The file exited 0. The two adversarial task-id cases both recorded pager-fix. The first used an FM_DATA_OVERRIDE outside a directory named data. The second ran inside the task directory with a relative brief.md. The same run covered the fallback-rule, profile-source, error-record and write-failure behaviour. I did not drive a Herdr or tmux primary. The decision log is written by a script, so the CLI run covers it.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Run the resolver on a brief under an FM_DATA_OVERRIDE root outside a data directory; the record has task pager-fix ✅ pass live dispatch-resolve-test.log
Run the resolver with relative brief.md inside the task directory; the record has task pager-fix ✅ pass live dispatch-resolve-test.log
Run the resolver on a brief under the home's data directory; the record has the task id, rule, 60-character rule text and profile, and no brief text ✅ pass live dispatch-resolve-test.log
Evidence: dispatch-resolve test transcript

Source: dispatch-resolve test transcript

ok - invalid preferred_provider: null
ok - invalid preferred_provider: false
ok - invalid preferred_provider: 42
ok - invalid preferred_provider: []
ok - invalid preferred_provider: {}
ok - invalid preferred_provider: ""
ok - invalid preferred_provider: "Codex"
ok - invalid preferred_provider: "codex\\n"
ok - invalid preferred_provider: " codex"
ok - preferred provider: astra-82-claude-26
ok - preferred provider: work-account
ok - preferred provider: exhausted
ok - preferred provider: unknown
ok - preferred provider: unknown-one-known-one
ok - preferred provider: claude-only
ok - preferred provider: config-override
ok - preferred provider: prose-why
ok - preferred provider: absent
ok - preferred provider: approval
ok - preferred provider: tie
ok - preferred provider: floor
ok - absent key is off: one stderr line, exit 0, no network call
ok - TYPESAFE_API_KEY= in .env activates the tool; environment and config overrides work
ok - clear: one rule Choice request, key on the fd header only, spendPriority argmax over every candidate
ok - TypeSafe base supports environment and .env overrides and rejects unsafe URLs before sending
ok - OpenRouter clear uses the same output contract and keeps its key out of argv and child environments
ok - OpenRouter ambiguous, malformed, HTTP, and missing-model paths are handled
ok - mapping: a declared macos-keychain service and optional account become the lookup, and the key rides the fd header
ok - precedence: environment, then .env, then the declared source, which is read only when needed
ok - provider isolation: each provider reads only its own declared service, and a declaration never selects a provider
ok - effective-home isolation: only the effective config directory's declaration is consulted
ok - failure distinctions: off, a configuration error, and an unavailable source each read differently and send nothing
ok - secret containment: the declared key is on no argv, in no output, environment, or file, and only on the fd header
ok - capability probe: supported or unsupported, with no declaration read and no credential tool run
ok - with no provider set, other providers' settings leave the original off line unchanged
ok - systemone posts the unchanged request to its base URL with an optional fd-3 key
ok - systemone configuration errors, never-send base URL, partial response, and transport failure are handled
ok - openai maps the Choice request to the Decisions API and its answer back, key on fd 3 only
ok - the never-send check runs on the final openai request body
ok - openai malformed, partial, refused, ambiguous, HTTP, and transport paths return to normal intake
ok - never-send list withholds the request on a match or a bad list, and never prints the value
ok - rules snapshots and shell quoting preserve the profile protocol
ok - quota_scope binds an agy candidate to its declared tier row
ok - no-rule fallback, Agy, Gemini, and documented configurations resolve
ok - ambiguous: confidence below the fixed floor hands the decision back
ok - task record: every exit-0 outcome records its decision for data/<id>/brief.md, and exit 2 records none
ok - task record: the configured data root, including FM_DATA_OVERRIDE, decides where the record goes
ok - per-rule confidence floors fall to the most probable runner-up that clears its own floor
ok - only the brief's task sections and scout tag reach the model, with a whole-brief fallback
ok - escalate: a rule declared approval: captain never yields a profile
ok - rule floor: known shortfall falls through while unavailable evidence escalates
ok - declared provider and profile floor evidence are applied in code
ok - nonnumeric spendPriority evidence is never ranked
ok - partial and missing quota evidence remain eligible but unranked
ok - provider-wide and exact quota rows combine into one limiting candidate
ok - default: no rule matched resolves among the default profiles
ok - tie: equal spendPriority never breaks by array order
ok - no rankable candidate: the tool escalates instead of guessing
ok - native Codex binds to codex-home before default, independently of Pi accounts and row order
ok - Pi native adapters bind to codex-home with existing fallbacks and schema 5 compatibility
ok - schema 6: each candidate binds to its account row; schema 5 is unchanged
ok - quota evidence comes from one quota-axi --json read, and its failure is an error outcome
ok - API, transport, and response failures are error outcomes with exit 0
ok - configuration errors exit 2 before any network call
ok - shared-quota opt-out: no quota snapshot, deterministic declared-order pick, opt-out stated on every candidate
ok - shared-quota bypasses an unmet rule-level floor: the rule's own profile wins with no quota call
ok - shared-quota bypasses an unmet profile-level floor: the first declared profile wins with no quota call
ok - shared-quota keeps preferred_provider narrowing: the preferred family wins in declared order with no quota call
ok - shared_quota false keeps the unchanged quota-ranked behavior
ok - resolution record: one line without brief text, nothing when off, write failures change nothing
# all fm-dispatch-resolve tests passed

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 3 issues found → auto-fixed ✅
  • ⚠️ bin/fm-dispatch-resolve.sh:489 - RECORD_PATH is fixed to $FM_HOME/state/dispatch-resolve.jsonl and ignores FM_STATE_OVERRIDE. docs/configuration.md:49 defines that variable as the runtime state directory. The peer scripts use ${FM_STATE_OVERRIDE:-$FM_HOME/state}, for example bin/fm-spawn.sh:820. Concrete sequence: a home sets both FM_DATA_OVERRIDE and FM_STATE_OVERRIDE. This is the kind of relocated setup the task-id fix supports. The resolver now records the correct task id, but it creates $FM_HOME/state and writes the log there. The configured state directory gets no line. If $FM_HOME is not writable, each resolution prints a warning and the line is lost. Remedy: use ${FM_STATE_OVERRIDE:-$FM_HOME/state} at :489. The same path is stated at :121-122 and docs/configuration.md:2304. This needs a decision because both documents name the home's state/ directory, and the stated intent covers only the task id.
  • ℹ️ bin/fm-dispatch-resolve.sh:122 - The header says task is "the <id> of data/<id>/brief.md, else null". That describes the removed path regex. task now comes from TASK_ID, which is set only when the brief's physical directory is directly under the configured data root (:250-253). Two cases contradict the header. A brief at &lt;FM_DATA_OVERRIDE&gt;/&lt;id&gt;/brief.md outside a directory named data now records its id. A data/&lt;id&gt;/brief.md outside the configured data root now records null. This text is also the --help output. Fix: write &lt;data&gt;/&lt;id&gt;/brief.md and refer to the &lt;data&gt; definition in the Task record paragraph (:104-105). docs/configuration.md:2305 says only "task id", so it is still correct.
  • ℹ️ tests/fm-dispatch-resolve.test.sh:2164 - The late-error rule_when assertion has no independent oracle. It computes the expected value with .rules[3].when[0:60], the same index and slice that emit_error uses. The public behavior is the documented 60-character excerpt in the record. The rule_4 text has fewer than 60 characters, so neither this assertion nor the literal one at :2099 tests truncation. If either record path stopped truncating (bin/fm-dispatch-resolve.sh:212 or when_of at :806), both assertions would still pass. Fix: give the matched rule a when longer than 60 characters, and compare both the clear and late-error records with a hand-written 60-character literal. That literal would reject a full or wrongly sliced rule text.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Run the resolver on a brief under an FM_DATA_OVERRIDE root outside a data directory; the record has task pager-fix ✅ pass live dispatch-resolve-test.log
Run the resolver with relative brief.md inside the task directory; the record has task pager-fix ✅ pass live dispatch-resolve-test.log
Run the resolver on a brief under the home's data directory; the record has the task id, rule, 60-character rule text and profile, and no brief text ✅ pass live dispatch-resolve-test.log
  • bash tests/fm-dispatch-resolve.test.sh (exit 0, all tests pass, including the task-id cases at lines ~2108-2120)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks for this, @Azd325.

I read tip 0121aa90 against main fc8972cd (6 ahead / 0 behind). CI is green and the PR is CLEAN. Contract-class: new-default — when typed dispatch resolution is configured, every API-reaching resolution now always appends to state/dispatch-resolve.jsonl with no separate gate. That is an always-on observer surface (FM-LEARN-4627), even though the resolver itself stays opt-in via TYPESAFE_API_KEY. New-default never auto-merges.

Diff looks safe (fail-soft local JSONL; no brief text / key; off path writes nothing). Self-rocket on the issue counts as 0 for triage.

Warm ask: the body marks live validation inconclusive (stubbed suite only). Could you live-drive one real resolution (clear / off / write-failure) against the product and post evidence, or re-raise through no-mistakes with that? Once live is in, this can be flagged for a captain merge-or-leave call — not auto-merged.

@Azd325

Azd325 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Live evidence on tip 0121aa90, macOS arm64, real TypeSafe API, a temporary FM_HOME with a real config/crew-dispatch.json and a real ship brief.

Scenario Result
Clear Exit 0, status: clear, profile claude/sonnet/medium. state/dispatch-resolve.jsonl got exactly one line with keys confidence, fallback_rule, probabilities, profile, profile_source, project, rule, rule_when, status, task, ts. Values: rule_2, confidence 0.94, profile_source: rule_2, fallback_rule: null. The line holds no brief text and no API key (checked with grep).
Off No key in the environment or in .env: the tool printed the off line and exited 0. state/ stayed empty: no record was written.
Write failure Record file set read-only: stdout and exit 0 were the same as in the clear case. stderr had one line: dispatch-resolve: could not write <FM_HOME>/state/dispatch-resolve.jsonl. The file still had one line.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @Azd325 — the live run covers exactly the three scenarios I asked about (clear writes one line with no brief/key, off writes nothing, read-only file keeps stdout/exit unchanged with a single stderr warning). Really appreciated.

Nothing else is needed from you right now. Tip 0121aa90 is unchanged, CI is green and the PR is CLEAN. Because the class is still new-default (always-on resolution record once typed dispatch is configured), this does not auto-merge; I'm passing it to the captain for a merge-or-leave call.

@Azd325
Azd325 force-pushed the fm/dispatch-resolve-decision-log branch from 0121aa9 to 8951d6c Compare November 1, 2026 18:41
@Azd325 Azd325 changed the title feat(bin): record each dispatch resolution in a local log feat(bin): record dispatch resolutions in a decision log Nov 1, 2026
@greptile-apps

greptile-apps Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; no blocking issue remains.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no blocking issue remains.

Reviews (4) · Last reviewed commit: "no-mistakes(review): Honor FM_STATE_OVER..." · Reviewed by Greptile

Comment thread bin/fm-dispatch-resolve.sh Resolved
Comment thread tests/fm-dispatch-resolve.test.sh Resolved
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @Azd325 for bringing this up to date. I re-checked the new head 83afb5f2 against main e1a7a2ff:

  • The attestation binds 83afb5f2, and every step completed.
  • Both Greptile P2s (rule_when on error records, and the latency glob in the test) are fixed and resolved, and the review is 5/5.
  • Quick checks pass, and the branch merges cleanly onto main.
  • About the 7 OpenAI assertions your test step saw fail on base: I ran tests/fm-dispatch-resolve.test.sh on this head with jq 1.7, and it passes end to end, including the resolution-record section. So those failures look tied to your local jq 1.8.2, not to the code.
  • Your 10-16 live run on the real TypeSafe API (clear writes one line with no brief or key, off writes nothing, a read-only file keeps stdout and the exit code) still covers the record's contract.

This is still a captain decision, waiting on Kun, not on you. Nothing more is needed from you. The contract-class is unchanged: new-default. Once typed dispatch is configured, every resolution is always recorded to state/dispatch-resolve.jsonl. So it stays a merge-or-leave call for Kun.

@Azd325
Azd325 force-pushed the fm/dispatch-resolve-decision-log branch from 83afb5f to 1156e04 Compare November 8, 2026 07:49
@Azd325 Azd325 changed the title feat(bin): record dispatch resolutions in a decision log feat(dispatch): record each dispatch resolution to a JSONL decision log Nov 8, 2026
Comment thread bin/fm-dispatch-resolve.sh Resolved
….test.sh by adding `|| exit` to all pushd/popd calls. This resolves Lint 2; Behavior portable parallel 1 failed in fm-lint.test.sh, which lints the same file. Dispatch-resolve tests pass locally; the full fm-lint test could not finish here because actionlint is not installed
…n/fm-dispatch-resolve.sh now records rule_when (first 60 chars of the matching rule's `when` from the rules snapshot, or the default text for `default`) when a valid answer exists. Checked the jq expression by hand on sample input. ci-3: tests/fm-dispatch-resolve.test.sh now normalises latency with sed -E 's/latency_ms: [0-9]+/latency_ms: N/' so the rest of stdout is compared in full. The existing late-error test also asserts rule_when. Not verified end to end: the full test file stops locally at 'openai clear status' ('response is not a rule Choice answer'), and it does so on unmodified HEAD too (local jq 1.8.2), so the new assertions and the red-when-changed check did not run
@Azd325
Azd325 force-pushed the fm/dispatch-resolve-decision-log branch from 1156e04 to e03b625 Compare November 28, 2026 21:09
@Azd325 Azd325 changed the title feat(dispatch): record each dispatch resolution to a JSONL decision log feat(dispatch-resolve): record each resolution in a JSONL decision log Nov 28, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @Azd325 for rebasing this. The head is now e03b625c on main 30dae608, and it merges cleanly.

What I checked: the attestation binds e03b625c with every step completed, the quick checks pass, Greptile is 5/5 on this head, and there are no threads. I re-read the record path. One JSON line per resolution that reached the API goes to ${FM_STATE_OVERRIDE:-$FM_HOME/state}/dispatch-resolve.jsonl. It records the task id, status, rule, the first 60 characters of the rule's when, confidence, probabilities, and the fallback rule and profile source, never the brief text or the key. The off path writes nothing, and a failed write only warns. Diff review: safe, no P1. A P3 for Kun only: the log is append-only with no rotation.

Overlap, for Kun: #8846 (@korabeland) now proposes a per-task copy of the printed answer beside each brief. It serves the same need, so Kun will likely pick one, or keep both on purpose. Nothing is needed from either of you for that.

This is still waiting on Kun's decision, not on you. The contract class is unchanged: new-default. Once typed dispatch is configured, every resolution is always recorded. The full suite hasn't run on this head yet. It's queued behind this pass's label budget.

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