Skip to content
This repository was archived by the owner on Sep 28, 2026. It is now read-only.

fix: normalize string tool results and preserve start-failure handles - #11

Merged
jnyross merged 6 commits into
mainfrom
fix/tool-result-normalization-and-handles
Aug 9, 2026
Merged

jnyross merged 6 commits into
mainfrom
fix/tool-result-normalization-and-handles

Conversation

@jnyross

@jnyross jnyross commented Aug 9, 2026 •

Copy link
Copy Markdown
Owner

Lab evidence (jnyross/mac-vm-testing-harness, branch codexgraph-vm-test @ 33777c7, worktree ~/Projects/mac-vm-harness--codexgraph-test)

Frozen candidate v1 (generated by the shipped skill, SHA-256 c891048a..., executed unchanged in ChatGPT Desktop Code Mode): all three feed workers 'failed to start' -> status blocked with live_handles [] while the three created threads kept running. Root cause proven by typeof diagnostic: the Code Mode tool returns its entire payload as a JSON string ({"threadId":...,"hostId":"local"}), and the generated findString key lookup cannot see into a string.

Frozen candidate v2 (v1 + exactly the two fixes in this PR, SHA-256 0debc233...): full 9-node pipeline executed on live feeds - D1-D3 fetch, I1 join, V1 gate, R1 repair, V2 revalidation, honest X1 terminal with digest_markdown, repair_used true, correct node accounting.

Changes

  1. references/code-mode-script-patterns.md + task-lifecycle.md: exact-envelope normalizeToolResult at every call boundary (parse the whole trimmed string once, keep raw in start_result, never fragment-extract from tool returns - fragment heuristics can discard multi-object payloads).
  2. Handle preservation: aggregate start errors must carry each rejected node's handle (Object.assign(err, { handles })); blocked results spread error.handles. Previously the aggregate throw dropped them - orphaned running tasks were unreported.
  3. Pending-setup resolution made explicitly non-optional, including projectless targets (v1's generated script refused with 'pending setup cannot be resolved for projectless tasks').
  4. Validator guidance: canonical URL comparison decodes HTML entities (&/&/&) - v2's only repair was consumed by this cosmetic mismatch in BBC RSS links.
  5. Regressions in the product repo (task_collection_harness): JSON-string tool returns (exact-once parse, raw kept, no fragment extraction), multi-start handle preservation, entity-normalized URL compare. Suite 10/10; validate_skill.py, graph_coherence --selfcheck, test_auto_release.py all pass.

Not claiming the product fully proven: the passed-status happy path with a regenerated (not hand-patched) script is the next scenario (Phase B).


Note

Low Risk
Documentation and test-harness changes for Code Mode orchestration patterns; no production runtime or auth/data paths.

Overview
Fixes Code Mode graph scripts misclassifying successful task starts and losing live tasks when parallel starts fail.

Tool result handling: resolveTool and direct tool calls now wrap returns with normalizeToolResult so JSON string payloads (e.g. codex_app__create_thread on Desktop) are parsed once into { value, raw } for ID lookup while start_result keeps the raw envelope—without fragment-extraction heuristics meant for model prose.

Start / blocked reporting: Required parallel starts build handles before each call, attach per-node handles on rejection, and aggregate failures with error.handles for blocked live_handles. Pending setup resolution is mandatory (including projectless targets via run tag only); findExactThread skips project ID matching when no project is bound.

Validators: Documents canonicalUrlForComparison so & / numeric entities do not trigger the single repair stage for equivalent URLs.

Harness: Exports normalizeToolResult, aggregateStartFailure, and canonicalUrlForComparison with unit tests for string parsing, handle preservation, and URL normalization.

Reviewed by Cursor Bugbot for commit 3f5e6a5. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of string-based tool results while preserving original details.
    • Task startup failures now retain available task handles for clearer recovery and blocked-state reporting.
    • Improved task setup resolution for projectless targets and partially created tasks.
    • URL comparisons now normalize common HTML entities and whitespace more reliably.
  • Documentation

    • Added guidance for tool-result handling, task lifecycles, and URL comparisons.
  • Tests

    • Added coverage for result parsing, task-handle preservation, and URL normalization.

Proven against real ChatGPT Desktop (macOS) in a Tart VM lab:
codex_app__create_thread returns its whole payload as a JSON string, so
key lookups on the raw return silently fail, converting every successful
start into a start failure and blocking the graph while the created
threads keep running unobserved (live_handles reported []).

- references: mandate exact-envelope normalizeToolResult at the call
  boundary (no fragment heuristics on tool returns; raw kept in
  start_result), make pending-setup resolution non-optional including
  projectless targets, and require aggregate start errors to carry every
  rejected node's handle into the blocked result
- validator guidance: decode HTML entities before URL comparison so
  & vs & does not consume the single repair allowance
- harness: add normalizeToolResult, aggregateStartFailure,
  canonicalUrlForComparison with regression coverage (10/10)
@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The change adds helpers for tool-result normalization, startup failure aggregation, and URL canonicalization. Lifecycle guidance now preserves live handles from rejected starts, resolves pending setup tasks, and verifies stringified tool results.

Changes

Task lifecycle robustness

Layer / File(s) Summary
Harness result and startup helpers
skills/codex-graph/scripts/task_collection_harness.js, skills/codex-graph/scripts/task_collection_harness.test.js
The harness adds and exports result-normalization and startup-failure helpers. Tests cover parsed results, raw-payload retention, non-JSON strings, and rejected handles.
Lifecycle result and handle handling
skills/codex-graph/references/code-mode-script-patterns.md, skills/codex-graph/references/task-lifecycle.md
Lifecycle guidance parses stringified results once, resolves pending setup tasks with bounded matching, and preserves handles from rejected required starts in blocked results.
URL comparison normalization
skills/codex-graph/scripts/task_collection_harness.js, skills/codex-graph/scripts/task_collection_harness.test.js, skills/codex-graph/references/code-mode-script-patterns.md
URL comparison now trims string URLs and decodes named, decimal, and hexadecimal HTML entities. Tests cover these conversions and null input.

Estimated code review effort: 2 (Simple) | ~15 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely summarizes the main changes: string tool-result normalization and preservation of start-failure handles.
Description check ✅ Passed The description clearly explains the behavior changes, validation results, regression coverage, and known limitation, although it does not use the repository template headings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/tool-result-normalization-and-handles

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

…hannel

Review feedback on the call-boundary example: drop the lastRawToolResult
global; call returns { value, raw } and the start site stores raw in
handle.start_result directly. Deduplicate the normalization rule - the
code and full contract live in code-mode-script-patterns.md; the task
lifecycle reference now points at it instead of repeating the block.
Matches the shape a freshly generated candidate adopted in the lab
(frozen-v3, executed to status passed).
cursor[bot]

This comment was marked as resolved.

call now returns { value, raw }; use value.value for agent ID
lookup and value.raw for spawnResult, matching the start-site pattern.
devin-ai-integration[bot]

This comment was marked as resolved.

Wire normalizeToolResult into both resolveTool call paths so the
canonical helper returns the {value,raw} envelope. Make findExactThread
require projectId only when one is bound so projectless pending setup
can resolve on the unique run tag.
devin-ai-integration[bot]

This comment was marked as resolved.

Collection must read wait/read fields from the normalizeToolResult value,
not the envelope. Required parallel starts create each handle first and
rethrow with it attached so aggregate failures can preserve live handles.
cursor[bot]

This comment was marked as resolved.

Pending-setup polling matches on handle.project_id; omit it and
project-bound workflows can bind the wrong thread or under-report.
@jnyross
jnyross merged commit d06ccb9 into main Aug 9, 2026
4 checks passed
@jnyross
jnyross deleted the fix/tool-result-normalization-and-handles branch August 9, 2026 10:59
jnyross added a commit that referenced this pull request Aug 9, 2026
…es (#16)

* feat: dynamic-workflow golden test cases from real Grok/Claude orchestration shapes

Turn curated Grok Rhai workflows (destination/hotel discovery funnels,
fixed-lane research DAGs) and Claude multi-agent patterns (disjoint
worktree implementers, review-scorer panels) into a maintainable
codex-graph test-case pack:

- docs/dynamic-workflow-testcase-catalog.md: source survey, shape
  analysis, tier/contract mapping, prioritized shortlist
- skills/codex-graph/testcases/: catalog.json + six case bundles
  (GOAL.md, EXPECTATIONS.md with fenced machine contract,
  topology.hint.mmd passing graph_coherence.py)
- testcases/harness/: offline expectations loader + static workflow.js
  checker (per-node env #14, read-first collection #13, node-local
  prompt scoping #12, result normalization #11) with CLI and 15 tests
- task_collection_harness.test.js: three pattern-derived fixtures
  (atomic screen fan-out terminal-at-first-read, screen-then-POV
  staged cardinality with root-owned fail-open, adversarial dual
  validators failing closed on malformed verdicts)
- both regression runners execute the new suite and lint the hints

Goals are synthetic and anonymized; no live Desktop run required.

* fix: harden expectations checker per PR #16 review

- collection:read-first / read-after-wait judge await-adjacent call
  sites only; parameter lists, bindings, and comments can no longer
  flip the verdict (v3 param-swap now fails; wrapper-based correct
  collectors are no longer false-failed)
- setup:pending-resolution requires bounded-resolution evidence
  (attempts constant or task-list poll) alongside the clientThreadId
  identifier; mentions-only scripts fail
- checkWorkflowText refuses vacuous ok on an empty contract
- atomic-screen-fanout goal genericized (composition/origin/month)
- disjoint-writers-worktree contract declares its drawn repair path
  (single_repair, R1, V2)
- four new negative/positive controls in testcases.test.js; README
  semantics updated to match the strengthened checks

* fix: fail collection checks when read/wait tools are absent

Await-adjacent matching correctly skips wrapper collectors, but treated
scripts with no read/wait bindings the same way and green-lit #13.
Require tool bindings when there are no await-adjacent call sites.

---------

Co-authored-by: Cursor Agent <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants