Skip to content

fix: preserve OpenCode session scope and output truncation - #76101

Open
pelikhan wants to merge 2 commits into
mainfrom
pelikhan/opencode-session-normalization
Open

pelikhan wants to merge 2 commits into
mainfrom
pelikhan/opencode-session-normalization

Conversation

@pelikhan

@pelikhan pelikhan commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Recognize OpenCode's native sessionID in shared session context while preserving existing canonical/legacy field precedence.
  • Map native v1/v2 boolean truncation metadata to typed tool.execution_complete.data.outputTruncated, retaining the flag in unified sessions without admitting provider metadata envelopes.
  • Generate both session schemas and document the truncation/scoping contract.
  • Add sanitized live-shaped regressions for true/false/absent/invalid truncation flags, snapshot reconciliation, and source-ordered accounting without double-counting turns or deduplicating source IDs.

Evidence and validation

Existing live Actions artifacts from 42539715763 and 41940497195 exposed missing session context and a dropped native grep truncation flag. Raw evidence remains private and is not committed.

Local replay of those archived native logs verifies every scoped core event has canonical session context, the observed truncation flag survives, provider metadata remains excluded, and usage totals/turn counts are unchanged. This is local replay, not new live execution.

  • Focused session/parser/projection/order/schema suites: 479 tests passed.
  • Final make agent-report-progress: passed; 262 impacted JavaScript tests passed, schema freshness and build passed. Existing lint warnings remain; no lint errors.
  • TypeScript typecheck and schema freshness: passed after the final gate.

Reconciled accounting retains source order and original timestamps, including timestamp regressions; this follows the existing ordering contract. No workflow dispatch, inference, MCP startup, or credential changes. Hosted CI and new live conformance execution remain unverified.

Recognize native sessionID context and project typed outputTruncated flags without exposing provider metadata. Preserve accounting reconciliation source order and add live-shaped regressions and schemas.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI auto review requested due to automatic review settings November 9, 2026 03:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Cross-session aggregate results are incorrectly attributed to the last result-producing session, corrupting per-session token and turn accounting.

1 open issue
What changed in this PR

This PR preserves OpenCode session identity and native output-truncation flags through gh-aw’s unified session pipeline, without exposing provider metadata.

Changes:

  • Recognizes native sessionID while preserving existing field precedence.
  • Carries boolean truncation flags through parsing, types, projection, and generated schemas.
  • Adds regressions for metadata filtering, snapshot reconciliation, and source-ordered accounting, and documents the contract.
File Description
docs/​src/​content/​docs/​specs/​unified-agent-session-specification.md Documents truncation, session scope, and accounting order.
docs/​public/​schemas/​unified-session.schema.json Adds boolean outputTruncated to unified completions.
docs/​public/​schemas/​agent-session.schema.json Adds boolean outputTruncated to canonical completions.
actions/​setup/​js/​unified_session_payload.cjs Preserves truncation in unified projection.
actions/​setup/​js/​types/​unified_session.d.ts Includes truncation in unified completion types.
actions/​setup/​js/​types/​agent_session.d.ts Defines the optional truncation field.
actions/​setup/​js/​scripts/​session_schemas.test.cjs Tests boolean truncation validation.
actions/​setup/​js/​parse_opencode_log.test.cjs Tests truncation, scoping, reconciliation, and accounting order.
actions/​setup/​js/​parse_opencode_log.cjs Extracts native truncation and clears stale flags.
actions/​setup/​js/​agent_session.test.cjs Tests native session identity and precedence.
actions/​setup/​js/​agent_session.cjs Adds native sessionID as a context fallback.

Review effort: Balanced (auto)

function sessionContext(event) {
const data = event?.data ?? {};
const sessionId = data.sessionId !== undefined ? data.sessionId : event?.sessionId !== undefined ? event.sessionId : event?.session_id !== undefined ? event.session_id : data.session_id;
const sessionId = data.sessionId !== undefined ? data.sessionId : event?.sessionId !== undefined ? event.sessionId : event?.session_id !== undefined ? event.session_id : data.session_id !== undefined ? data.session_id : event?.sessionID;
Preserve canonical outputTruncated and merged structuredContent fields; regenerate session schemas from combined declarations.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
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