Skip to content

feat: OpenCode Observability Plugin#73

Open
billxbf wants to merge 9 commits into
NVIDIA:mainfrom
billxbf:feature/bx-opencode
Open

feat: OpenCode Observability Plugin#73
billxbf wants to merge 9 commits into
NVIDIA:mainfrom
billxbf:feature/bx-opencode

Conversation

@billxbf
Copy link
Copy Markdown

@billxbf billxbf commented May 8, 2026

Overview

  • I confirm this contribution is my own work, or I have the right to submit it under this project's license.
  • I searched existing issues and open pull requests, and this does not duplicate existing work.

Details

  • Adds integrations/opencode-plugin as an npm package for OpenCode server plugin usage.
  • Exports ATOF JSONL events and ATIF session trajectories.
  • Records config, session lifecycle, chat metadata, LLM request metadata, and successful tool spans.
  • Adds plugin tests, README usage docs, OpenCode integration docs, and an integration plan.
  • Quick interactive run path:
    • build crates/node
    • install or use stock opencode
    • write opencode.json with the plugin file URL
    • start opencode and inspect .nemoflow output

example opencode.json

{
  "plugin": [
    [
      "file://$NEMO_FLOW_REPO/integrations/opencode-plugin",
      {
        "enabled": true,
        "atofPath": "./.nemoflow/opencode.atof.jsonl",
        "atifPath": "./.nemoflow/opencode.atif.json",
        "logPath": "./.nemoflow/opencode-plugin.log"
      }
    ]
  ]
}

Where should the reviewer start?

Start with integrations/opencode-plugin/server.js, then review integrations/opencode-plugin/test/server.test.mjs.

Summary by CodeRabbit

  • New Features

    • OpenCode Plugin integration available for passive observability in NeMo Flow, with configurable output paths and session tracking; packaged for Node runtimes.
  • Documentation

    • Added comprehensive guides and integration docs detailing configuration, installation, demo workflow, and output inspection.
  • Tests

    • New test suite verifying plugin hooks, session lifecycle, output generation, pass-through and failure behaviors.
  • Chores

    • Repository now ignores .nemoflow directories to avoid tracking generated outputs.

@billxbf billxbf requested review from a team as code owners May 8, 2026 19:22
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 8, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Review Change Stack

Walkthrough

This PR adds an OpenCode server plugin package, core server implementation, docs, and tests that record OpenCode session/message/tool events into NeMo Flow and emit ATOF JSONL and ATIF trajectory files with safe serialization and graceful runtime-fallback behavior.

Changes

NeMo Flow OpenCode Plugin Integration

Layer / File(s) Summary
Package Configuration & Environment Setup
.gitignore, integrations/opencode-plugin/package.json
ES module package @nvidia/nemoflow-opencode-plugin with exports to ./server.js, test script, Node/OpenCode engine constraints, nemo-flow-node local dependency, peer/dev @opencode-ai/plugin, and VCS ignore pattern **/.nemoflow/.
Core Plugin Implementation
integrations/opencode-plugin/server.js
OpenCode server plugin implementing runtime loading, safe JSON serialization (redaction, BigInt, Error), per-session state and scope management, lazy ATOF JSONL exporter registration/deregistration, ATIF trajectory export on session flush, mark emission into NeMo Flow, tool span handling, and pass-through when runtime fails to initialize.
Integration Guides & README
docs/index.md, docs/integrate-frameworks/about.md, docs/integrate-frameworks/opencode.md, integrations/opencode-plugin/README.md
Adds integration guide and README with build/install/demo instructions, opencode.json configuration examples (plugin path and output locations), verification commands, sequence diagram of export flow, pass-through/failure checks, and API limitations (passive observability only).
Test Suite & Validation
integrations/opencode-plugin/test/server.test.mjs
Comprehensive tests with fake runtime and temp helpers covering core hook recording, lifecycle events, secret redaction, missing-session filtering, disabled-mode pass-through, and runtime-load-failure logging and behavior.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits format with type 'feat' and a concise imperative summary under 72 characters, accurately reflecting the main change.
Description check ✅ Passed The description includes all required sections: Overview with confirmed checkboxes, detailed change breakdown, reviewer guidance on where to start, and relevant context with example configuration.
Docstring Coverage ✅ Passed Docstring coverage is 85.19% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

@github-actions github-actions Bot added size:XL PR is extra large feat PR introduces new feature or functionality lang:js PR changes/introduces Javascript/Typescript code labels May 8, 2026
@billxbf
Copy link
Copy Markdown
Author

billxbf commented May 8, 2026

/retest

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@integrations/opencode-plugin/server.js`:
- Around line 214-216: The subscriber registered via
lib.registerSubscriber(using atofSubscriberName) writes with
fsSync.appendFileSync(options.atofPath, ...) with no error handling; wrap the
appendFileSync call inside a try/catch inside the subscriber callback, and on
error log or swallow the error (use existing logger or console.error) so
ENOSPC/EACCES or other sync I/O failures do not throw out of the event delivery
path; keep the callback signature and behavior otherwise unchanged so NeMo
Flow/framework behavior is preserved.
- Around line 33-60: The write function currently lets filesystem errors bubble
up and reject plugin hooks; wrap the entire body of write (the path-handling,
ensureParentDir, fs.appendFile and the console logging branches) in a try/catch
so any thrown error is swallowed (or downgraded to a non-fatal fallback) and
write always resolves; on fs failures fall back to console logging the same
formatted message (include PLUGIN_ID, message and toJsonSafe(extra)), and ensure
warnOnce/info/warn/error callers (and the seen set logic) continue to return a
resolved Promise rather than letting errors propagate from write (keep the
existing Promise.resolve() return for the seen shortcut). Use the existing
symbols write, PLUGIN_ID, logPath, ensureParentDir, fs.appendFile, toJsonSafe
and seen to locate where to add the try/catch and fallback.
- Around line 197-198: recentFlushes is an unbounded Map used as a 2s dedupe
cache and needs pruning; change its entries so each key maps to insertion
timestamp (or schedule a per-key setTimeout) and remove entries older than 2
seconds. Locate the recentFlushes usage in server.js (the const recentFlushes =
new Map() declaration and any code that checks/sets keys) and: when adding a
key, store Date.now() (or schedule a setTimeout to delete that key after
2000ms); when checking a key, consider it expired if its timestamp is >2000ms
old and delete it before proceeding; optionally add a short periodic cleanup
(setInterval) to remove stale keys if you choose timestamp-based approach.
Ensure the semantics of the dedupe window remain 2 seconds and that no other
code relies on Map values being non-timestamps.
- Around line 1-2: Replace the line-style SPDX header comments at the top of
integrations/opencode-plugin/server.js with a C-style comment block;
specifically, change the two leading single-line comments containing
"SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES.
All rights reserved." and "SPDX-License-Identifier: Apache-2.0" into a single /*
... */ block so the file has a C-style SPDX header as required by the repo's
licensing guidelines.
- Around line 251-259: In withStack, always restore the prior thread scope stack
instead of only when previous is truthy: capture priorStack via
lib.currentScopeStack(), set lib.setThreadScopeStack(session.stack) before
running callback, and in the finally block call
lib.setThreadScopeStack(previousStack) (even if previousStack is undefined) so
the thread scope is always reset; reference the withStack function and the
lib.currentScopeStack / lib.setThreadScopeStack calls to locate where to change
the restore logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: ff9f6b37-40d8-4c6f-8698-7fab042a2722

📥 Commits

Reviewing files that changed from the base of the PR and between cb849b9 and 1eb3d52.

📒 Files selected for processing (1)
  • integrations/opencode-plugin/server.js
📜 Review details
🧰 Additional context used
📓 Path-based instructions (12)
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Use camelCase naming convention for Node.js code

Files:

  • integrations/opencode-plugin/server.js
**/*.{rs,go,js,ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Include SPDX license headers in all Rust, Go, JavaScript, and TypeScript source files using C-style comment syntax

Files:

  • integrations/opencode-plugin/server.js
**/*.{rs,py,go,js,ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Use SONAR_IGNORE_START / SONAR_IGNORE_END markers only for documented false positives that cannot be resolved in code; keep ignored blocks small, add explanatory comments, and require reviewer sign-off

Files:

  • integrations/opencode-plugin/server.js
**/*.{md,markdown,py,sh,bash,js,ts,java,cpp,go,rust}

📄 CodeRabbit inference engine (.agents/skills/contribute-docs/SKILL.md)

Keep package names, repo references, and build commands current in documentation

Files:

  • integrations/opencode-plugin/server.js
**/*.{md,markdown,py,sh,bash,js,ts,example}

📄 CodeRabbit inference engine (.agents/skills/contribute-docs/SKILL.md)

Example commands must match current package names and paths

Files:

  • integrations/opencode-plugin/server.js
**/{integrations,integration,*-integration}/**

📄 CodeRabbit inference engine (.agents/skills/contribute-integration/SKILL.md)

**/{integrations,integration,*-integration}/**: Keep NeMo Flow optional in framework integrations
Preserve the framework's original behavior when NeMo Flow is absent
Wrap tool and LLM paths at the correct framework boundary
Integration pattern must follow docs/integrate-frameworks/adding-scopes.md

Files:

  • integrations/opencode-plugin/server.js
{crates/adaptive/**,python/nemo_flow/{adaptive,plugin}.py,go/nemo_flow/{adaptive,**}/*.go,**/*.{ts,js,wasm}}

📄 CodeRabbit inference engine (.agents/skills/maintain-optimizer/SKILL.md)

Keep adaptive config schema, plugin lifecycle, and bindings in sync across crates/adaptive, core, bindings, Python (python/nemo_flow/adaptive.py and python/nemo_flow/plugin.py), Go (go/nemo_flow/adaptive and go/nemo_flow), and Node/WebAssembly helpers

Files:

  • integrations/opencode-plugin/server.js
**/*.{js,ts,tsx,jsx,py,rs,go,java,c,cpp,h,cc,cxx,cs,rb,php,swift,kt}

📄 CodeRabbit inference engine (.agents/skills/prepare-pr/SKILL.md)

Changed files must be formatted with the language-native formatter

Files:

  • integrations/opencode-plugin/server.js
**/*.{rs,py,js,ts,go,sh,toml,yaml,yml,json,md,rst}

📄 CodeRabbit inference engine (AGENTS.md)

Keep SPDX headers on source, docs, scripts, and configuration files. The project is Apache-2.0.

Files:

  • integrations/opencode-plugin/server.js
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

If Node.js language surface changed, always run Node.js test target even when Rust core did not change

Files:

  • integrations/opencode-plugin/server.js
**/*.{py,js,ts,tsx,go,rs,md}

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

Format changed files with the language-native formatter before the final lint/test pass

Files:

  • integrations/opencode-plugin/server.js
**/*.{rs,py,js,ts,tsx,go}

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

During iteration, prefer uv run pre-commit run --files <changed files...> for targeted validation

Files:

  • integrations/opencode-plugin/server.js

Comment on lines +1 to +2
// SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use a C-style SPDX header in this JavaScript file.

The repo requires JS SPDX headers in C-style comment syntax; the current // form can be missed by license tooling.

Suggested fix
-// SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
-// SPDX-License-Identifier: Apache-2.0
+/*
+ * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */

As per coding guidelines, **/*.{rs,go,js,ts,tsx}: Include SPDX license headers in all Rust, Go, JavaScript, and TypeScript source files using C-style comment syntax.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@integrations/opencode-plugin/server.js` around lines 1 - 2, Replace the
line-style SPDX header comments at the top of
integrations/opencode-plugin/server.js with a C-style comment block;
specifically, change the two leading single-line comments containing
"SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES.
All rights reserved." and "SPDX-License-Identifier: Apache-2.0" into a single /*
... */ block so the file has a C-style SPDX header as required by the repo's
licensing guidelines.

Comment on lines +33 to +60
async function write(level, message, extra) {
const record = {
timestamp: new Date().toISOString(),
level,
plugin: PLUGIN_ID,
message,
...(extra === undefined ? {} : { extra: toJsonSafe(extra) }),
}
const line = JSON.stringify(record) + "\n"
if (logPath) {
await ensureParentDir(logPath)
await fs.appendFile(logPath, line)
return
}
const text = `[${PLUGIN_ID}] ${message}`
if (level === "error") console.error(text, extra ?? "")
else if (level === "warn") console.warn(text, extra ?? "")
else console.info(text, extra ?? "")
}

return {
info: (message, extra) => write("info", message, extra),
warn: (message, extra) => write("warn", message, extra),
error: (message, extra) => write("error", message, extra),
warnOnce: (key, message, extra) => {
if (seen.has(key)) return Promise.resolve()
seen.add(key)
return write("warn", message, extra)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Do not let logger I/O failures reject plugin hooks.

write() currently propagates filesystem errors. An unwritable .nemoflow directory can turn plugin initialization into a rejected load, and every fire-and-forget void logger.* call elsewhere becomes an unhandled rejection. The logger should swallow/fallback internally so observability failures stay non-fatal.

As per coding guidelines, **/{integrations,integration,*-integration}/**: Keep NeMo Flow optional in framework integrationsandPreserve the framework's original behavior when NeMo Flow is absent`.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@integrations/opencode-plugin/server.js` around lines 33 - 60, The write
function currently lets filesystem errors bubble up and reject plugin hooks;
wrap the entire body of write (the path-handling, ensureParentDir, fs.appendFile
and the console logging branches) in a try/catch so any thrown error is
swallowed (or downgraded to a non-fatal fallback) and write always resolves; on
fs failures fall back to console logging the same formatted message (include
PLUGIN_ID, message and toJsonSafe(extra)), and ensure warnOnce/info/warn/error
callers (and the seen set logic) continue to return a resolved Promise rather
than letting errors propagate from write (keep the existing Promise.resolve()
return for the seen shortcut). Use the existing symbols write, PLUGIN_ID,
logPath, ensureParentDir, fs.appendFile, toJsonSafe and seen to locate where to
add the try/catch and fallback.

Comment on lines +197 to +198
const recentFlushes = new Map()
const trajectories = []
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Expire recentFlushes; this dedupe cache currently grows forever.

The map is only used for a 2s duplicate-flush window, but entries are never pruned. On a long-lived OpenCode process it grows with every completed session.

Also applies to: 343-343, 402-403

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@integrations/opencode-plugin/server.js` around lines 197 - 198, recentFlushes
is an unbounded Map used as a 2s dedupe cache and needs pruning; change its
entries so each key maps to insertion timestamp (or schedule a per-key
setTimeout) and remove entries older than 2 seconds. Locate the recentFlushes
usage in server.js (the const recentFlushes = new Map() declaration and any code
that checks/sets keys) and: when adding a key, store Date.now() (or schedule a
setTimeout to delete that key after 2000ms); when checking a key, consider it
expired if its timestamp is >2000ms old and delete it before proceeding;
optionally add a short periodic cleanup (setInterval) to remove stale keys if
you choose timestamp-based approach. Ensure the semantics of the dedupe window
remain 2 seconds and that no other code relies on Map values being
non-timestamps.

Comment on lines +214 to +216
lib.registerSubscriber(atofSubscriberName, (event) => {
fsSync.appendFileSync(options.atofPath, JSON.stringify(event) + "\n")
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Contain ATOF export write failures inside the subscriber callback.

appendFileSync() is executed directly on the subscriber path with no error handling. ENOSPC/EACCES here will throw synchronously while the runtime is delivering events, which can break the host flow instead of degrading observability only.

As per coding guidelines, **/{integrations,integration,*-integration}/**: Keep NeMo Flow optional in framework integrationsandPreserve the framework's original behavior when NeMo Flow is absent`.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@integrations/opencode-plugin/server.js` around lines 214 - 216, The
subscriber registered via lib.registerSubscriber(using atofSubscriberName)
writes with fsSync.appendFileSync(options.atofPath, ...) with no error handling;
wrap the appendFileSync call inside a try/catch inside the subscriber callback,
and on error log or swallow the error (use existing logger or console.error) so
ENOSPC/EACCES or other sync I/O failures do not throw out of the event delivery
path; keep the callback signature and behavior otherwise unchanged so NeMo
Flow/framework behavior is preserved.

Comment on lines +251 to +259
function withStack(session, callback) {
if (!session.stack || typeof lib.setThreadScopeStack !== "function") return callback()
const previous = typeof lib.currentScopeStack === "function" ? lib.currentScopeStack() : undefined
lib.setThreadScopeStack(session.stack)
try {
return callback()
} finally {
if (previous) lib.setThreadScopeStack(previous)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

fd -t f "server.js" integrations/

Repository: NVIDIA/NeMo-Flow

Length of output: 99


🏁 Script executed:

wc -l integrations/opencode-plugin/server.js

Repository: NVIDIA/NeMo-Flow

Length of output: 103


🏁 Script executed:

sed -n '245,265p' integrations/opencode-plugin/server.js

Repository: NVIDIA/NeMo-Flow

Length of output: 695


🏁 Script executed:

head -50 integrations/opencode-plugin/server.js

Repository: NVIDIA/NeMo-Flow

Length of output: 1456


🏁 Script executed:

rg "setThreadScopeStack|currentScopeStack" integrations/opencode-plugin/server.js -B 2 -A 2

Repository: NVIDIA/NeMo-Flow

Length of output: 459


🏁 Script executed:

rg "setThreadScopeStack|currentScopeStack" --type js --type ts

Repository: NVIDIA/NeMo-Flow

Length of output: 619


🏁 Script executed:

cat crates/wasm/wrappers/esm/index.js

Repository: NVIDIA/NeMo-Flow

Length of output: 3030


🏁 Script executed:

rg "export.*setThreadScopeStack|export.*currentScopeStack" --type js

Repository: NVIDIA/NeMo-Flow

Length of output: 42


🏁 Script executed:

find crates -name "*.rs" -type f | xargs rg "fn setThreadScopeStack|fn currentScopeStack" -A 5

Repository: NVIDIA/NeMo-Flow

Length of output: 44


🏁 Script executed:

find crates/adaptive -name "*.rs" | head -20

Repository: NVIDIA/NeMo-Flow

Length of output: 882


🏁 Script executed:

rg "setThreadScopeStack|currentScopeStack" crates/adaptive/ -A 3 -B 1

Repository: NVIDIA/NeMo-Flow

Length of output: 42


🏁 Script executed:

rg "setThreadScopeStack" crates/ -A 3 -B 1

Repository: NVIDIA/NeMo-Flow

Length of output: 6336


🏁 Script executed:

fd -e rs -e ts -e js | xargs rg "pub fn setThreadScopeStack|pub.*setThreadScopeStack" -A 5

Repository: NVIDIA/NeMo-Flow

Length of output: 44


🏁 Script executed:

rg "thread.*scope.*stack|scope.*stack.*thread" crates/ --type rs -i

Repository: NVIDIA/NeMo-Flow

Length of output: 87


🏁 Script executed:

cat crates/wasm/src/api/mod.rs | sed -n '1,100p'

Repository: NVIDIA/NeMo-Flow

Length of output: 4343


🏁 Script executed:

rg "bind_thread_scope_stack|set_thread_scope_stack" crates/ --type rs -B 2 -A 8

Repository: NVIDIA/NeMo-Flow

Length of output: 87


🏁 Script executed:

cat crates/node/tests/context_tests.mjs | grep -A 20 "setThreadScopeStack isolates"

Repository: NVIDIA/NeMo-Flow

Length of output: 849


🏁 Script executed:

rg "pub fn set_thread_scope_stack|pub.*setThreadScopeStack" crates/wasm/src/api/mod.rs -A 10

Repository: NVIDIA/NeMo-Flow

Length of output: 478


🏁 Script executed:

rg "TASK_SCOPE_STACK|set_thread_scope_stack" crates/node/src/api/mod.rs -B 2 -A 10

Repository: NVIDIA/NeMo-Flow

Length of output: 6474


🏁 Script executed:

cat crates/node/tests/context_tests.mjs | grep -B 5 -A 15 "Switch back to stack1"

Repository: NVIDIA/NeMo-Flow

Length of output: 510


🏁 Script executed:

rg "currentScopeStack.*undefined|undefined.*setThreadScopeStack" crates/node/tests/ -B 3 -A 3

Repository: NVIDIA/NeMo-Flow

Length of output: 42


🏁 Script executed:

cat crates/node/tests/context_tests.mjs | grep -B 10 -A 10 "original = currentScopeStack"

Repository: NVIDIA/NeMo-Flow

Length of output: 1591


Always restore the previous scope stack.

If currentScopeStack() returns no prior stack, the finally block leaves session.stack installed on the thread. Subsequent marks/spans can then inherit the wrong session scope and corrupt cross-session telemetry.

Suggested fix
 function withStack(session, callback) {
   if (!session.stack || typeof lib.setThreadScopeStack !== "function") return callback()
   const previous = typeof lib.currentScopeStack === "function" ? lib.currentScopeStack() : undefined
   lib.setThreadScopeStack(session.stack)
   try {
     return callback()
   } finally {
-    if (previous) lib.setThreadScopeStack(previous)
+    lib.setThreadScopeStack(previous)
   }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function withStack(session, callback) {
if (!session.stack || typeof lib.setThreadScopeStack !== "function") return callback()
const previous = typeof lib.currentScopeStack === "function" ? lib.currentScopeStack() : undefined
lib.setThreadScopeStack(session.stack)
try {
return callback()
} finally {
if (previous) lib.setThreadScopeStack(previous)
}
function withStack(session, callback) {
if (!session.stack || typeof lib.setThreadScopeStack !== "function") return callback()
const previous = typeof lib.currentScopeStack === "function" ? lib.currentScopeStack() : undefined
lib.setThreadScopeStack(session.stack)
try {
return callback()
} finally {
lib.setThreadScopeStack(previous)
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@integrations/opencode-plugin/server.js` around lines 251 - 259, In withStack,
always restore the prior thread scope stack instead of only when previous is
truthy: capture priorStack via lib.currentScopeStack(), set
lib.setThreadScopeStack(session.stack) before running callback, and in the
finally block call lib.setThreadScopeStack(previousStack) (even if previousStack
is undefined) so the thread scope is always reset; reference the withStack
function and the lib.currentScopeStack / lib.setThreadScopeStack calls to locate
where to change the restore logic.

@@ -0,0 +1,55 @@
{
"name": "@nvidia/nemoflow-opencode-plugin",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"name": "@nvidia/nemoflow-opencode-plugin",
"name": "nemo-flow-opencode",

"atof",
"plugin"
],
"homepage": "https://github.com/NVIDIA/NeMo-Flow#readme",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should link to docs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be necessary.

Add integrations/opencode to the root package.json

```

When the plugin package is published, use
`@nvidia/nemoflow-opencode-plugin` in the OpenCode config instead of the local
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package should be: nemo-flow-opencode

{
"plugin": [
[
"file:///absolute/path/to/NeMo-Flow/integrations/opencode-plugin",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we will be publishing a node package, we should refer to the node package name itself.

Suggested change
"file:///absolute/path/to/NeMo-Flow/integrations/opencode-plugin",
"nemo-flow-opencode",

Comment on lines +248 to +263
## Demo Video Script

Use this storyboard to record a short walkthrough.

| Shot | Show | Narration |
|---|---|---|
| 1 | `opencode.json` with the plugin file URL | Stock OpenCode loads the NeMo Flow plugin through normal plugin config. |
| 2 | `opencode debug info` output | OpenCode sees the plugin without applying an OpenCode patch. |
| 3 | `opencode run` or the interactive OpenCode UI | The developer uses OpenCode normally. |
| 4 | `ls -la .nemoflow` | The plugin writes observability files in the background. |
| 5 | `grep` against `opencode.atof.jsonl` | ATOF contains session, message, LLM request, and tool lifecycle events. |
| 6 | `jq` against `opencode.atif.json` | ATIF contains the exported session trajectory. |
| 7 | Disabled or forced-failure smoke | OpenCode still runs when the plugin is disabled or pass-through. |

Keep the recording focused on the user-visible contract: install the plugin,
use OpenCode normally, and inspect `.nemoflow` output after the session.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the purpose of this. The document here is for end users. Documentation should be relevant to them, not to developers

setThreadScopeStack(_stack) {},
pushScope(name, scopeType, _parent, attributes, data, metadata, input) {
const handle = {
uuid: `scope-${++counter}`,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a valid UUID. When in doubt, let UUIDs be generated automatically.

Comment on lines +20 to +32
{
"plugin": [
[
"file:///absolute/path/to/NeMo-Flow/integrations/opencode-plugin",
{
"enabled": true,
"atofPath": "./.nemoflow/opencode.atof.jsonl",
"atifPath": "./.nemoflow/opencode.atif.json",
"logPath": "./.nemoflow/opencode-plugin.log"
}
]
]
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is okay for now, but the configuration shape should be relatively consistent across all integrations (and support plugins in the future)

model: modelName(input.model),
})
if (!session) return
emitMark(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a mark and not llmCall ?

model: modelName(input.model ?? output?.message?.model),
})
if (!session) return
emitMark(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a mark and not llmCallEnd ?

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

Labels

feat PR introduces new feature or functionality lang:js PR changes/introduces Javascript/Typescript code size:XL PR is extra large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants