Skip to content

Fix Cursor native session normalization - #76109

Merged
pelikhan merged 3 commits into
mainfrom
pelikhan/cursor-session-normalization
Nov 9, 2026
Merged

pelikhan merged 3 commits into
mainfrom
pelikhan/cursor-session-normalization

Conversation

@pelikhan

@pelikhan pelikhan commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fix the concrete Cursor normalization defects observed in the existing conformance run, without changing the pinned engine version, credentials, or inference behavior.

  • Exclude hookAdditionalContexts and other metadata from tool execution events; preserve unknown observations as opaque Cursor events rather than fabricating calls.
  • Normalize native reasoning deltas/completion markers and safe millisecond timestamps.
  • Map observed model-call correlations and retain distinct terminal answer text with its request correlation and result status, without duplicating an already observed answer.
  • Normalize native cache read/write aliases through the existing usage validation/precedence/overflow contract so unified projection retains cache accounting.
  • Add sanitized live-shape regressions, update sample documentation/changeset, and regenerate both affected Cursor workflow locks. Raw envelopes, RPC compaction and unrelated shared projections remain unchanged.

Evidence and validation

Local replay of the downloaded conformance log now produces 6 tool starts, 6 completions, 43 reasoning events, 57 native timestamps, zero phantom hook tools, and preserves 95,360 cache-read tokens, zero cache-write tokens, and the distinct terminal answer. This is local replay of existing evidence, not a newly executed Actions run.

Passed:

  • make build && make fmt
  • make lint-cjs (no errors; existing repository warnings remain)
  • make recompile — all 365 workflows compiled
  • go test ./pkg/workflow -run '^TestCursor' -count=1
  • Runtime typecheck, session schema freshness, and 542 focused JavaScript tests covering session normalization, usage, ordering, rendering and telemetry
  • Final make agent-report-progress test groups passed. Its Go lint hit another session's global linter lock; all remaining non-test gates passed on make agent-report-progress-no-test with a private TMPDIR, including Go lint and full workflow drift validation. test-unit was not rerun.

Integration dependency / unverified coverage

The adapter emits tool messageId correlations. Their retention in the final unified tool projection depends on the separately owned Pi shared-projection fix; this PR deliberately does not duplicate that shared ownership. Assistant model-call/request correlations already survive the existing projection.

No new workflow dispatch, inference, MCP startup, or credential change was performed. The recent smoke run stopped on an invalid API key and provides no structured runtime coverage. Failed-tool and subagent mapping remain unverified live where absent from the captured evidence; these historical runs are not rewritten.

@pelikhan
pelikhan marked this pull request as ready for review November 9, 2026 03:24
Copilot AI adaptive review requested due to automatic review settings November 9, 2026 03:24
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

❌ PR Specification Reviewer failed to deliver outputs. Please review the logs for details.

Generated by PR Specification Reviewer for #76109

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

❌ Ponytail Reviewer failed. Please review the logs for details.

Warning

Threat detection engine error

Threat detection could not complete its analysis due to a tooling error. This is not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs to troubleshoot the error.

Generated by Ponytail Reviewer for #76109

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

Design Decision Gate 🏗️

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Design Decision Gate 🏗️ · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 8.6K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 7.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions github-actions Bot 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.

Reviewed head d8e34eb against Unified Agent Session Specification v2.7.0, especially T-UAS-005, T-UAS-006, T-UAS-007, T-UAS-012–015, and T-UAS-020. The implementation is aligned with the existing normative preservation, metadata, timestamp, tool, result, and usage obligations. The PR makes prior informative Cursor coverage statements stale: sanitized stream-json live-shape evidence is now present, while live failed-tool, subagent, and latest-release coverage remains unverified. I synchronized docs/src/content/docs/specs/unified-agent-session-specification.md to draft v2.7.1 (2026-11-09), updating Sections 7.9, 9.4, 9.6, and the change log without changing normative requirements. The specification commit is queued for publication on this PR branch. No blocking conformance finding identified. Coverage is static: no tests or workflows were executed by this review.

Generated by PR Specification Reviewer for #76109 · copilot · gpt50 · ~5 AIC · ⌖ ~2 AIC · ⊞ 1.7K
Comment /review-specs to run again

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-09T03:27:19Z
review_event: REQUEST_CHANGES
top_themes: cache alias precedence; unsafe overflow-key iteration; terminal-answer deduplication
files_reviewed: actions/setup/js/agent_session.cjs, actions/setup/js/agent_session.test.cjs, pkg/workflow/cursor_workflow_test.go, .github/workflows/shared/cursor.md
comment_count: 3

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~4 AIC · ⌖ ~1 AIC · ⊞ 1.6K · ◷
Comment /review to run again

@github-actions github-actions Bot 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.

I found three correctness issues that can silently lose session data or crash usage normalization.

Findings
  • Cache alias selection stops at the first present, even invalid, alias.
  • Unknown overflow markers can now throw during normalization.
  • Session-wide answer deduplication can drop a legitimate repeated terminal answer and its correlation.

Please address these edge cases before merge.

Comments that could not be inline-anchored

actions/setup/js/agent_session.cjs:79

This alias lookup can discard valid cache evidence when an earlier alias is present but invalid, causing cache accounting to disappear. <details><summary>💡 Prefer the first valid alias</summary> `find` currently selects the first present alias, not the first alias whose value passes `isTokenCount`; for example, `{cacheReadTokens: "bad", cache_read_tokens: 5}` yields no canonical cache count. Select the first valid alias (or continue searching after invalid values), while preserving canonical-...

actions/setup/js/agent_session.cjs:146

This loop now throws when `overflowed_tokens` contains an unknown key, turning malformed or stale usage metadata into a parser crash. <details><summary>💡 Ignore or validate unknown overflow keys</summary> `USAGE_ALIASES[key]` is undefined for foreign keys, so `for (const alias of USAGE_ALIASES[key])` raises `TypeError`. The previous single-property delete was harmless. Guard with an own-key check or iterate `(USAGE_ALIASES[key] ?? [])` so unknown overflow markers remain non-fatal. </details>

actions/setup/js/agent_session.cjs:251

This session-wide text search can suppress a legitimate terminal answer when an earlier assistant turn used the same content, losing the final result and its request correlation. <details><summary>💡 Scope deduplication to the current result</summary> The `some` predicate matches any prior `assistant.message` with equal text and also treats two missing session IDs as equal. Deduplicate only the message produced by the same model/request or the immediately preceding normalized event, so repeate...

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~4 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again

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

Cursor omits separate cache usage from session totals, and rejected cache values can reappear in token accounting through lower-priority aliases.

2 open issues
What changed in this PR

This PR corrects Cursor native-log normalization in gh-aw, preserving session evidence without changing the engine version, credentials, or inference behavior.

Changes:

  • Filters tool metadata and normalizes reasoning, timestamps, correlations, and distinct terminal answers.
  • Adds cache-token aliases with validation and overflow handling.
  • Adds regression coverage, updates sample documentation, and regenerates both Cursor workflow locks.
File Description
pkg/​workflow/​cursor_workflow_test.go Adds native Cursor event and unified-projection regressions.
actions/​setup/​js/​agent_session.test.cjs Tests cache aliases, precedence, validation, and overflow.
actions/​setup/​js/​agent_session.cjs Extends shared usage normalization with native cache aliases.
.github/​workflows/​smoke-cursor.lock.yml Regenerates the smoke workflow with parser updates.
.github/​workflows/​shared/​cursor.md Updates the Cursor parser and documents evidence coverage.
.github/​workflows/​engine-conformance-cursor.lock.yml Regenerates the conformance workflow with parser updates.
.changeset/​patch-cursor-session-normalization.md Records the normalization fixes as a patch release.

Review effort: Balanced (auto)

Comment thread .github/workflows/shared/cursor.md Resolved
Comment thread actions/setup/js/agent_session.cjs Resolved

@github-actions github-actions Bot 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.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd. Requesting changes because the shared usage normalizer can drop a valid token count.

📋 Findings and notes

Blocking

  • Alias precedence (agent_session.cjs:79): the lookup picks the first present alias, so an invalid camelCase value hides a valid alias. Reproduced on HEAD. Fix: select by isTokenCount.
  • Latent throw (agent_session.cjs:101, 124, 146): non-canonical overflow keys make USAGE_ALIASES[key] undefined. Current callers appear sanitized, so this is not blocking, but the ?? [] guard is cheap.

Non-blocking

  • Dedup scope (cursor.md:260): the result fallback matches only on content, so sessionless runs can suppress a repeated final answer.
  • Tool filter: non-*ToolCall native tool shapes now fall through to cursor.tool_call. Confirm this is intended and add a test.
  • Integration dependency: messageId retention in the final tool projection depends on the Pi shared projection change. Confirm that lands with this PR.

Positive

  • ✅ Lock files match the source parser at HEAD.
  • ✅ The changeset is an accurate patch entry.
  • ✅ The assistant.reasoning mapping and timestamp validation are covered by tests.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~7 AIC · ⌖ ~2 AIC · ⊞ 6.3K
Comment /matt to run again

Comment thread actions/setup/js/agent_session.cjs Resolved
Comment thread actions/setup/js/agent_session.cjs Resolved
Comment thread .github/workflows/shared/cursor.md Resolved
Sync main snapshot 1b6cb00, preserving Cursor fixes and regenerated workflow/session artifacts.

Co-authored-by: Copilot App <[email protected]>
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (actions/setup/js/agent_session.cjs:79): address unresolved feedback - Review comment
  3. Review (actions/setup/js/agent_session.cjs:146): address unresolved feedback - Review comment
  4. Review (.github/workflows/shared/cursor.md:260): address unresolved feedback - Review comment

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "5a4bfc454b2801ceea49405d8aa3d562101fea71",
  "kind": "requested",
  "schema_version": "1",
  "state": "2b96c5f971a786fa50c4cf32a07bea070e06d28466ee058e4b9338b1c5ac7ef7",
  "work": [
    "037d198a8d5660bee26f6ba2e058650cf480f9c3462849ee56d886a5bacbcdb8",
    "a5012a56d74f24ce98e98ecb961e5db0755b5cc2d941045b7e46cf860431eb63",
    "cd03f182e3412dfcaeee297635f941393b25d83c9a54012da21666f3f9bad70f"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · haiku45 · ~9 AIC · ⌖ ~13 AIC · ⊞ 1.3K · ◷
Comment /souschef to run again

Include separate cache usage in Cursor totals, prevent invalid alias resurrection, normalize overflow markers safely, and scope terminal-answer deduplication.

Co-authored-by: Copilot App <[email protected]>
@pelikhan

pelikhan commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

In reply to the specification reviewer status: I inspected the failed step. The agent completed, but publishing its specification patch was blocked because the workflow token could not read branch-protection metadata; I am keeping that permission failure separate from the Cursor fixes and have not changed credentials or bypassed the protection.

@pelikhan

pelikhan commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

In reply to the Ponytail reviewer status: The failed step was secret redaction, which removed the artifact and failed closed with ERR_VALIDATION. This is unavailable reviewer evidence, not a security finding; I have not weakened redaction or rerun the workflow.

@pelikhan

pelikhan commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

In reply to the code quality review status: I addressed the resulting alias-validation, overflow-key and terminal-answer feedback with focused regressions. Presence-based alias precedence remains intentional, so the contradictory suggestion to substitute a lower-priority valid value is declined explicitly in its inline thread.

@pelikhan

pelikhan commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

In reply to the design decision gate: No additional design change is requested by this reported_no_action notice. The fixes preserve the existing canonical session contract; I am not treating the no-op status as proof of runtime completeness.

@pelikhan

pelikhan commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

In reply to the test quality status: The review notices require no independent code change, but the concrete feedback is now covered by cache-total, alias-rejection, hostile overflow-key and scoped terminal-answer regressions. The reported_no_action status is not being used as a substitute for those checks.

@pelikhan

pelikhan commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

In reply to the skills review status: I fixed overflow safety and terminal-answer scoping, and added regressions for the native tool-shape boundary and cache accounting. The first-valid alias suggestion is declined because it contradicts property-presence precedence and can resurrect explicitly rejected usage; tool messageId projection remains a separately tracked Pi integration dependency.

@pelikhan

pelikhan commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

In reply to the saved review themes: The matching findings are addressed by rejected-alias cleanup, guarded overflow processing and tighter terminal-answer deduplication, with regressions. I have left the workflow-managed comment-memory block unchanged.

@pelikhan
pelikhan merged commit 1d23568 into main Nov 9, 2026
109 checks passed
@pelikhan
pelikhan deleted the pelikhan/cursor-session-normalization branch November 9, 2026 04:21

Copilot AI commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:...

Merged latest main in fb2bced. The assigned review fixes and regressions are already present in 818a793; both Cursor locks are current. Focused and final impacted tests passed. CodeQL timed out and instructed not to retry.

@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.2

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.

4 participants