Skip to content

replay to dev - #7

Open
sdevare-nv wants to merge 7 commits into
sdd/devfrom
sdd/replay
Open

replay to dev#7
sdevare-nv wants to merge 7 commits into
sdd/devfrom
sdd/replay

Conversation

@sdevare-nv

Copy link
Copy Markdown
Owner

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Please provide a description of the issue, the changes you made to fix it, and why they work. It is expected that you understand why your changes work and if you do not understand why at least say as much so a maintainer knows how much to value the PR.

If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!

How did you verify your code works?

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

sdevare-nv and others added 4 commits July 10, 2026 17:58
…ontinue)

Gym's swe_agents wrapper can already resume an OpenHands run from a partial
trajectory (REPLAY_MESSAGES_PATH); this wires the same capability into the
opencode bench harness.

run_infer.sh gains a new $13 REPLAY_MESSAGES_PATH positional arg, forwarded
to bench/cli.ts as --replay-messages-file. cli.ts parses the replay file
(bench/replay.ts, mirroring OpenHands' messages_to_replay_events() skip
rules: system/tool/subsequent-user messages are skipped, the first user
message becomes the task instruction verbatim, and each assistant message
becomes a scripted turn) and threads the scripted turns into the nemo-gym
provider's config instead of gym's rendered user_message.txt.

NemoGymLanguageModel answers the first N doStream/doGenerate calls (main
session only) from that scripted queue by synthesizing the same kind of
stream it already builds from a real HTTP response, instead of making one.
Tool calls in that synthesized stream still get executed for real by
opencode's normal streamText -> resolveTools() -> Tool.execute() path
(unchanged) — required for correctness, since SWE-bench agents mutate a git
workspace and the final patch comes from `git diff`: a replayed edit/bash
call has to actually happen on the fresh container, not just be asserted via
stale recorded output text. Scripted turns are never dumped to
completionsDir, so gym's replay/live boundary detection (first dumped
completion's cumulative message count) still lines up on the first live
call. Once the queue drains, both methods fall through unchanged to the
existing real-HTTP path and the agent continues live — no changes needed to
session/processor.ts, session/prompt.ts, or any HTTP route.
…ubsequent user messages

Critical fix: replay never actually activated in a real opencode run. The
previous check compared the resolved session id to a literal "main" sentinel,
but session/llm.ts sets `x-session-affinity: input.sessionID` unconditionally
for every call on the nemo-gym provider — including the top-level session's
own calls — so sessionID is always the real session id (e.g. "ses_...") and
never equals "main". Every call fell through to a live HTTP request with no
replay context at all, which is exactly the "starts solving from the
beginning" symptom. Fixed by gating on `parentSessionID` presence (the actual
signal for "this is a subagent session") instead.

A second, related bug: opencode's own runLoop forks off title-generation and
summary-generation model calls on step 1, using the SAME session id as the
real agentic loop. Those race ahead of the loop's own first call and, once
the sessionID check above was fixed, would otherwise silently consume
scripted replay turns meant for the real agent (confirmed happening in
practice). They're reliably distinguishable because they never pass `tools` —
only the real agentic loop resolves and sends the tool registry — so
`_popReplayTurn` now also requires `hasTools`.

Verified end-to-end against a real opencode run (not just unit tests, which
didn't set a `headers` object and so never exercised either bug): a 2-turn
scripted replay against a real git workspace now correctly re-executes both
bash tool calls for real (workspace shows the replayed edit, `git diff` is
non-empty) before falling through to a live call whose message list includes
the full replay prefix.

Also adds subsequent-user-message support: a user message anywhere after the
trajectory's first one is real request content the model must see, not an
action to replay. bench/replay.ts now returns them attached to the replay
turn they precede (or as trailing texts, if the trajectory ends on a user
message); NemoGymLanguageModel splices them into the outgoing message list —
and the llm_completions dump gym reads — on every live call from the point
replay reaches them onward, since opencode's own session storage isn't
writable from this provider.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Sugam Devare <sdevare@nvidia.com>
@github-actions

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • No "Type of change" checkbox is checked. Please select at least one.
  • No issue referenced. Please add Closes #<number> linking to the relevant issue.
  • "How did you verify your code works?" section is empty. Please explain how you tested.
  • Not all checklist items are checked. Please confirm you have tested locally and have not included unrelated changes.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown

Hey! Your PR title replay to dev doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant