replay to dev - #7
Open
sdevare-nv wants to merge 7 commits into
Open
Conversation
…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>
sdd/dev to replay
Signed-off-by: Sugam Devare <sdevare@nvidia.com>
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
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. |
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #
Type of change
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
If you do not follow this template your PR will be automatically rejected.