Skip to content

refactor: share OpenCode payload helpers between the Action and the gateway - #1872

Merged
marcusrbrown merged 6 commits into
mainfrom
refactor/shared-payload-accessors
Oct 19, 2026
Merged

marcusrbrown merged 6 commits into
mainfrom
refactor/shared-payload-accessors

Conversation

@marcusrbrown

Copy link
Copy Markdown
Collaborator

Problem

The Action and the gateway each kept their own copies of the OpenCode payload helpers: 26 own-property accessors spread over 7 files, the task-notice regex and parser, the event-shape helpers, and the blocking-tool-part check. A comment in run-core.ts said it "mirrors streaming.ts exactly", but nothing enforced that, so a fix on one side could miss the other.

Change

The shared helpers now live once in @fro-bot/runtime (packages/runtime/src/agent/):

Module Exports
payload-accessors.ts ownValue, getStringProperty, getNumberProperty, getBooleanProperty, getObjectProperty
event-shape.ts getSessionID, getEventKind, getEventPayload, getEventSessionID
task-notice.ts parseTaskNotice, parseSyntheticNoticePart, TaskNotice
message-facts.ts hasBlockingToolPart
  • Action: streaming.ts, session-poll.ts and retry.ts import the shared helpers. The local copies are deleted. The root-session gate around parseTaskNotice stays at the call site.
  • Gateway: run-core.ts, drain-completion.ts and both approvals coordinators import the shared helpers. The local copies and the "mirrors" comments are deleted.

Kept separate on purpose:

  • The REST message readers. Their selection rules differ: the Action picks by time.created, the gateway by array order.
  • firstString in error-format/provider-failure.ts. It rejects empty strings for classification, while the plain accessors accept them.

The consolidation requirements doc now marks the provider-failure classifier (#1869) as delivered. It says a drift guard is needed only while copies remain, and none remain after this PR.

Behaviour

No behaviour change and no contract bump. The function bodies moved as written, and the task-notice regex is byte-identical. The existing Action and gateway suites pass with no test edits.

Verification

  • bun run check-types, bun run lint, bun run build all pass. dist/ is rebuilt because runtime is bundled into the Action.
  • Tests: runtime 1177, action 2602, workspace-agent 773, harness 439, gateway 5330, evals 173, scripts 688.
  • New unit tests cover each shared module. A revert-check (replacing an own-property read with a bracket read) fails the inherited-property and getter tests.

@fro-bot fro-bot left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Verdict: PASS

The extraction preserves existing behavior, including own-property reads, null/undefined distinctions, task-notice guards, and tool-completion exemptions. No actionable correctness, security, or public API regression found.

Blocking issues

None

Non-blocking concerns

None

Missing tests

None

Risk assessment (LOW/MED/HIGH): likelihood of regression, security exposure, or blast radius

LOW. Shared helpers retain the original semantics, with focused new unit coverage and existing caller-level regression tests. Review was based on diff, source, and test inspection; build, lint, type checks, and test suites were not run.


Run Summary
Field Value
Event pull_request
Repository fro-bot/agent
Run ID 39294639766
Cache hit
Session ses_eaac5ff39ffe7eDJjgy1QFpZKO

@marcusrbrown
marcusrbrown merged commit 801fc25 into main Oct 19, 2026
15 checks passed
@marcusrbrown
marcusrbrown deleted the refactor/shared-payload-accessors branch October 19, 2026 17:56
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.

2 participants