Skip to content

fix(orchestrator): timestamp-based comment-walk for input-required (#35)#36

Open
nitzanvolman wants to merge 1 commit into
vnovick:mainfrom
nitzanvolman:fix/issue-35-input-required-loop
Open

fix(orchestrator): timestamp-based comment-walk for input-required (#35)#36
nitzanvolman wants to merge 1 commit into
vnovick:mainfrom
nitzanvolman:fix/issue-35-input-required-loop

Conversation

@nitzanvolman
Copy link
Copy Markdown

Summary

Fixes #35.

recoverInputRequired and checkTrackerReplies (internal/orchestrator/event_loop.go) walked detailed.Comments by array position, implicitly assuming chronological order. Linear's GraphQL comments(first: 50, orderBy: createdAt) (internal/tracker/linear/queries.go:53) returns comments newest-first by default. On Linear, the reverse-index walk finds the oldest 🤖 comment, then the forward walk traverses older comments — so any non-🤖 comment in the issue's history is misread as a fresh user reply. checkTrackerReplies deletes the state.InputRequiredIssues entry and dispatches a "resumed" worker; recoverInputRequired returns nil for the same reason. Both safety paths fail simultaneously, producing the 49-loop documented in the issue.

Fix

Replace the two index-walks with helpers that compare domain.Comment.CreatedAt timestamps:

  • findLatestItervoxComment — scans the full slice, returns the index/CreatedAt of the most recently created 🤖-prefixed comment. No ordering assumption.
  • firstReplyAfter(comments, t) — returns the body of the first non-🤖 comment with CreatedAt > t. Conservatively skips comments with nil CreatedAt.

recoverInputRequired and checkTrackerReplies are rewritten to use these helpers. Behaviour is correct on Linear (descending), GitHub (ascending), and any other ordering.

Test plan

  • New whitebox test file internal/orchestrator/event_loop_internal_test.go (9 cases): descending-order Linear-style with no reply, descending with reply, ascending with no reply, ascending with reply, no comments, nil CreatedAt, and checkTrackerReplies regression cases for both orderings.
  • The two descending-order regression tests fail against main's event_loop.go and pass under this fix.
  • go test -race ./internal/orchestrator/... — green
  • go test -race -count=5 ./internal/orchestrator/... — green (no flakes)
  • make verify — exit 0 (fmt, vet, golangci-lint, full Go race tests, web 45 files / 409 tests, spelling guard)

Out of scope (follow-ups, not in this PR)

  • Async fire-and-forget 🤖 posting (event_loop.go:967-973) has no retry; if the tracker rejects the comment, recovery still loses its anchor.
  • Codex worker break ordering (worker.go:452 runs before :461) can drop the input-required signal entirely for Codex when the sentinel isn't in the last 3 text blocks of the final agent message.
  • Distinguishing agent-posted vs human-posted comments (e.g. via author identity or a hidden marker) for defense-in-depth.

🤖 Generated with Claude Code

…novick#35)

`recoverInputRequired` and `checkTrackerReplies` walked comments by array
position, implicitly assuming chronological order. Linear's GraphQL
`comments(first: 50, orderBy: createdAt)` returns newest-first, inverting
the logic: the "last" 🤖 comment becomes the oldest in the array, and any
non-🤖 comment in the issue's history is misread as a fresh user reply.
`checkTrackerReplies` then deletes `state.InputRequiredIssues` and
dispatches a "resumed" worker; `recoverInputRequired` returns nil for the
same reason. Both safety paths fail simultaneously, producing the 49-loop
documented in vnovick#35.

Replace the index-walks with two helpers — `findLatestItervoxComment` and
`firstReplyAfter` — that compare `domain.Comment.CreatedAt` timestamps.
Result is correct regardless of whether the tracker returns comments
ascending or descending, and conservatively skips comments with nil
CreatedAt rather than mistreating them.

Adds 9 whitebox tests in a new same-package file covering Linear-descending,
GitHub-ascending, real user replies, nil CreatedAt, and the empty-comments
edge case. The two descending-order regression cases failed against the
previous logic and pass under the fix.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@nitzanvolman nitzanvolman changed the base branch from main to pre-release May 8, 2026 04:32
@nitzanvolman nitzanvolman changed the base branch from pre-release to main May 8, 2026 04:32
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.

Issues remain dispatch-eligible despite repeated <!-- itervox:needs-input --> emissions

1 participant