theam / theam/facility

Queued reviewer prompt omits the preceding builder response

Open
#306 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
71
Forks
64
Avg merge
15h 38m
Merged PRs (30d)
66

Description

Problem

A review requested before a builder finishes can start without the builder's final response in its shared conversation context. The response remains stored, but buildPrompt excludes it because its message sequence is greater than the review request's sequence.

Observed on main at f7ab74a0931b85df3d8725cca3678f3d1d37c84d.

Reproduction

  1. Start a builder turn in a story.
  2. Before that turn completes, queue a request for pr-reviewer: "Review the builder's result."
  3. Let the builder finish with a response such as "Implementation complete; integration tests were not run because the test service was unavailable."
  4. Dispatch the queued reviewer turn and inspect its prompt.

The conversation now has this order:

Sequence Role Turn Message
1 user builder Implement the change
2 user reviewer Review the result
3 agent builder Final result and verification limitations

buildPrompt retains only messages with seq <= 2, dropping the predecessor's result. Requesting the same review after the builder completes includes that result instead.

Expected behavior

When a queued turn starts, it receives available responses from predecessor turns as well as its own request. Later queued user requests must remain excluded, and the current request should remain the final message in the supplied transcript.

Evidence and impact

Reproduced using the unchanged buildPrompt function with deterministic message histories matching queueMessage and completeTurn sequencing. The queued case omits the handoff; the request-after-completion control includes it. This is a local prompt-construction reproduction, not a production incident or a live-model evaluation.

  • Prompt cutoff: services/api/src/turns/dispatcher.ts, buildPrompt.
  • Sequence assignment: services/api/src/stories/service.ts, queueMessage and completeTurn.
  • Activation preserves the queued request's sequence: activateNextMessage.

A newly selected reviewer may receive the changed worktree without the predecessor's explanation of incomplete verification or other important decisions. Native session persistence for the builder does not supply that context to a different agent's first session.

Proposed fix and acceptance

Select preceding user messages and responses associated with their turns, including responses appended after the current request was queued. Keep the current request last and exclude later queued requests and their responses.

Add deterministic prompt tests and a database-backed dispatcher regression covering a builder, a queued reviewer with no prior native session, and an additional future request. Preserve the existing behavior for normal sequential conversations. No database migration or manifest change is needed; long-history summarization is separate follow-up work.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with buildPrompt in services/api/src/turns/dispatcher.ts, then trace queueMessage and completeTurn in services/api/src/stories/service.ts and activateNextMessage. Add deterministic prompt tests and a database-backed dispatcher regression covering a builder, queued reviewer, and later request. Done means predecessor responses are included, later queued requests remain excluded, the current request is last, and normal sequential behavior is preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.