Skip to content

fix(bin): read the last result event when a Claude engine turn returns an array - #6264

Open
AnPod wants to merge 1 commit into
kunchenguid:mainfrom
AnPod:cursor/fix-engine-result-verbose-array-6194
Open

AnPod wants to merge 1 commit into
kunchenguid:mainfrom
AnPod:cursor/fix-engine-result-verbose-array-6194

Conversation

@AnPod

@AnPod AnPod commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #6194.

When the supervision host's Claude engine runs with verbose settings, --output-format json prints a JSON array of events instead of one result object. fm_supervision_engine_result only accepted an object, so every such turn was counted as failed even though the result event at the end of the array was complete.

For an array, the parser now uses the last event with type: "result". Every existing completeness check (error flag, subtype, usage fields, turn count, cost accounting) still runs on that event. An array with no result event fails the turn, and so does an earlier success followed by a failed or incomplete final result. Plain objects behave as before. I updated the function comment and docs/supervision-host.md to match.

Tested:

  • New test_engine_result_objects_and_verbose_arrays in tests/fm-supervision-host.test.sh passes. It covers a plain object, a verbose array, trailing non-result events, a missing result, and an error, non-success or incomplete final result after an earlier success.
  • shellcheck on the two changed shell files is clean.

Not run:

  • The full supervision-host suite and the full bin/fm-lint.sh (the full lint was too slow in my environment). The box has Node 20, and the rest of the host suite hit unsupported .ts loading.
  • Bash 3.2 / macOS.
  • No git push no-mistakes attestation yet. This PR was prepared on the fork and I will push it through no-mistakes myself, so the attestation check will fail until then.

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Engine result parsing now handles verbose event arrays.

The PR appears safe to merge; the remaining test-fidelity suggestion is non-blocking.

Reviews (3) · Last reviewed commit: "fix(bin): read the last result event whe..."

Comment on lines +2617 to +2627
total_cost_usd: 1.25, num_turns: 3, usage: {input_tokens: 11,
cache_read_input_tokens: 22, cache_creation_input_tokens: 33, output_tokens: 44}};
const final = JSON.parse(JSON.stringify(success));
const variant = process.argv[2];
const events = [null, {type: "system"}, success];
if (variant === "missing") events.pop();
if (variant === "subtype") final.subtype = "error_during_execution";
if (variant === "is-error") final.is_error = true;
if (variant === "incomplete") delete final.usage.output_tokens;
if (["subtype", "is-error", "incomplete"].includes(variant)) events.push(final);
if (variant === "trailing") events.push({type: "system"}, null);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Synthetic arrays leave format unverified

Every verbose array in this test is built from a result object the test also creates. That checks the parser against the assumed event shape, but it could pass even if Claude's actual verbose output still fails to parse. A captured verbose response or an opt-in live-engine case would cover the format this fix is meant to support.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

VISION.md per-rule

  • One captain, one interface: aligns — stops false engine-turn failures from drowning the captain with late wakes.
  • Authority is explicit and never inferred: aligns — no new autonomy; accounting only.
  • Scripts own the mechanics, agents own the judgment: aligns — parser picks last type:\"result\" from a verbose array; completeness checks unchanged.
  • A restart is a non-event: aligns — no durability change.
  • Delegation with a spine: aligns — supervision host result contract restored for verbose Claude JSON.
  • The fleet outlives any vendor: aligns — Claude engine adapter reads vendor-exposed shape (object or event array).
  • Scope: aligns — fm_supervision_engine_result + docs/tests only.

contract-class: restore — unconfigured path already counted Claude engine turns via fm_supervision_engine_result; tip vs main adds last-result selection when --output-format json emits a verbose event array. Plain objects unchanged. Greptile P2 (synthetic fixtures) is review signal only, not blocking.

Waiting on you (not a captain hold): PR must be raised via no-mistakes is red — body has no Pipeline attestation naming head 6ad63f5aff3d60af7535319dcf9988fa267f24fc (you noted this in the PR body). Please run git push no-mistakes so the body attests this head. CI behavior lanes look green otherwise. Closes #6194 when landed.

@AnPod
AnPod force-pushed the cursor/fix-engine-result-verbose-array-6194 branch from 6ad63f5 to 806ca88 Compare October 1, 2026 05:27
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: re-stamp after head moved to 806ca883 (prior stamp was 6ad63f5a) vs tip 549e07f37fd73aa01d74cd126b1111c99175abed. Closes #6194: yes. Tip fm_supervision_engine_result still requires a plain object (no last-type:\"result\" unwrap for verbose arrays).

Attestation: MISSING (body still says no git push no-mistakes yet). NM FAILURE. Lint 1 FAILURE — ambient bin/fm-teardown.sh reason=memory (~8.4 GiB RSS) under the 12 GiB address-space cap; this PR does not touch teardown. Behavior portable + Herdr otherwise green. Greptile SUCCESS (P2 synthetic-fixtures note only). MERGEABLE/UNSTABLE. Author AnPod not blocked.

contract-class: restore — unconfigured path already counted Claude engine turns via fm_supervision_engine_result; tip vs main adds last-result selection when verbose JSON is an event array. Plain objects unchanged.

VISION (per-rule)

  • One captain, one interface: aligns — stops false engine-turn failures / late wakes.
  • Authority: aligns — no new autonomy; accounting only.
  • Scripts own mechanics: aligns — parser picks last type:\"result\"; completeness checks unchanged.
  • Restart / Delegation / Fleet / Scope: aligns — Claude engine adapter reads vendor-exposed shape.

Waiting on you: git push no-mistakes so the body attests head 806ca883. Lint1 memory is tip-wide on fm-teardown.sh (see also #6271's 16 GiB envelope); re-push or rebase may still hit it until that lands. Not otherwise-ready → no Firstmate flag.

…s an array

Claude's verbose output returns a turn as a JSON array of events, which
the supervision engine rejected. Read the last result event from such
an array, keeping the completeness checks and cost accounting.

Closes kunchenguid#6194
@AnPod
AnPod force-pushed the cursor/fix-engine-result-verbose-array-6194 branch from 806ca88 to 2cb301c Compare October 5, 2026 05:52
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: re-stamp for the new head 2cb301c0 (prior stamp was 806ca883). It is waiting on you, the author, for one thing only: the no-mistakes attestation. It is not a captain hold.

Tip check: main f470a01c fm_supervision_engine_result still accepts only a plain object. This head picks the last type: "result" event from a verbose array and keeps every existing completeness check. Closes #6194: yes.

Gates on this head:

  • CI run 37269688547 is all green, including Lint 1, which failed on the earlier head.
  • Greptile 5/5. Its P2 about synthetic fixtures is not blocking.
  • Attestation MISSING. PR must be raised via no-mistakes run 37269688137 is FAILURE. The body still says it has not been raised.
  • No workflow files changed.

contract-class: restore (unchanged). The default path already counts Claude engine turns through this parser. Verbose array output was being miscounted as failed. Plain objects behave as before.

VISION (per rule): unchanged. One captain/one interface (no false failed-turn wakes), authority explicit, scripts own the mechanics, restart is a non-event, delegation with a spine, fleet outlives any vendor (it reads both shapes the vendor emits), and scope all align.

What unblocks it: run git push no-mistakes so the body attests head 2cb301c0. Once the gate is green, this is otherwise ready to merge as a restore.

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.

Supervision host counts every Claude engine turn as failed when Claude Code's verbose setting is on

2 participants