Skip to content

fix(sessions): distinguish Codex typed prompts from injected context - #2034

Open
XY-code1 wants to merge 6 commits into
Tencent:mainfrom
XY-code1:fix/codex-human-prompts
Open

XY-code1 wants to merge 6 commits into
Tencent:mainfrom
XY-code1:fix/codex-human-prompts

Conversation

@XY-code1

@XY-code1 XY-code1 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Codex rollouts can record both human input and injected context as user-role messages. This change distinguishes them for scoring and task extraction without removing any transcript content.

Behavior and scope

  • Recognize both legacy user_message events and newer item_completed events with a UserMessage item.
  • Match user-role messages by trimmed text and occurrence count. If both event formats record the same text, use the larger count rather than adding them.
  • Mark unmatched user-role messages as synthetic so the shared typed-input reader skips them. If neither event format is present, preserve the previous behavior.
  • Scope is limited to Codex scoring and task extraction. Dashboard counters, Claude Code, Hermes, and malformed-line reporting are unchanged. Real rollouts where event text differs from message text still need validation.

Test Plan

  • npx vitest run src/__tests__/session-codex-title.test.ts --retry 0

    Test Files  1 passed (1)
         Tests  6 passed (6)
    

    The regressions cover duplicated legacy/scoped events, missing response turn metadata, and separate scoped + unscoped completed prompts with identical text.

  • npm run typecheck

    > tsc --noEmit && tsc -p oxlint-plugin-teamai
    # exit 0
    
  • Targeted type-aware lint and whitespace validation

    $ npx oxlint --type-aware --deny-warnings --report-unused-disable-directives packages/tool-core/src/formats/codex.ts src/__tests__/session-codex-title.test.ts
    # exit 0, no findings
    $ git diff --check
    # exit 0
    
  • Representative real-CLI verification on Debian Linux, Node v24.22.3, 2026-11-27.

    Verdict: VERIFIED: Codex × git × project scope via teamai session show --source codex.

    $ npm run verify:world
    World /tmp/teamai-verify/20261127T011401-473893
    Build c7eb1778b3d4, teamai 0.22.0, sha256 08374c9877dc
    20261127T011401-473893
    
    $ npm run -s verify -- doctor 20261127T011401-473893
    ok   node v24.22.3
    ok   git version 2.39.5
    ok   world 20261127T011401-473893 at /tmp/teamai-verify/20261127T011401-473893
    ok   world built from c7eb177; checkout is at c7eb177
    
    $ npm run -s verify -- teamai 20261127T011401-473893 init https://teamai.test/team/repo.git --provider git --agent claude
    ✔ teamai initialized successfully!
    
    # Planted a seven-record Codex rollout in the world's isolated CODEX_HOME:
    # two genuine "Continue." responses, one unscoped completed event and one
    # turn-scoped completed event, followed by an assistant response.
    $ npm run -s verify -- teamai 20261127T011401-473893 session show 019b0000-0000-7000-8000-000000002034 --source codex
    ### user
    Continue.
    
    ### user
    Continue.
    
    ### assistant
    Done.
    
    $ npm run -s verify -- ledger 20261127T011401-473893
    Ledger: CLEAN
    Written to /tmp/teamai-verify/20261127T011401-473893/LEDGER-1.md
    

    The world was then cleaned successfully with npm run -s verify -- cleanup 20261127T011401-473893.

Refs #1989

@XY-code1 XY-code1 added the bug Something isn't working label Nov 23, 2026
@XY-code1

Copy link
Copy Markdown
Collaborator Author

Follow-up: For UserMessage events with a turn ID, the transcript reader now matches both the turn ID and the text. Earlier injected text from outside that turn no longer consumes the match. Events without a turn ID retain text-based matching.

The new regression failed on the previous PR head (the synthetic flags were reversed) and passed after the fix. All four Codex fixture tests and targeted type-aware lint passed locally. Real-CLI verification is still pending.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Deduplicate scoped matches against legacy counts — packages/tool-core/src/formats/codex.ts:780. When one prompt has both a legacy user_message event and a turn-scoped item_completed event, matching it consumes only scoped, leaving its legacy allowance available. An injected message with identical text then also counts as typed input. Adding a legacy event to the new “Continue.” fixture reproduces this.

  • [P1 blocking] Fall back to text matching when response turn metadata is absent — packages/tool-core/src/formats/codex.ts:720. A UserMessage event with turn_id goes exclusively into scoped. If the corresponding user response lacks internal_chat_message_metadata_passthrough, neither lookup matches, even with identical text. The genuine prompt becomes synthetic and disappears from scoring and task extraction.

  • [P1 blocking] Document a representative real-CLI verification — PR description, “Test Plan”. This changes runtime behavior, but the required verification remains unchecked. Adapter fixtures, typecheck, lint, and a reference to CI results do not document a successful real-CLI run, as required by Code Review Rules.

@XY-code1

Copy link
Copy Markdown
Collaborator Author

Addressed the three blocking findings in 35b82b0:

  • scoped prompt counts now reserve/deduct their duplicate legacy allowance, with the “Continue.” fixture covering both event formats;
  • responses without turn metadata fall back to an unreserved scoped text match, while exact later turn matches remain protected from earlier injected messages;
  • the PR Test Plan now records the focused tests, typecheck, targeted lint, and the attempted real-CLI verification. The verifier reports the run as UNVERIFIABLE because this host is Windows and has neither a normal WSL distribution nor an available Docker Linux engine.

Local results: 5 focused tests passed; typecheck, targeted type-aware lint, and git diff --check passed.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Preserve unscoped completed-event allowances — packages/tool-core/src/formats/codex.ts:751. For two genuine “Continue.” prompts recorded only as item_completed, one without turn_id and one with matching response turn metadata, subtracting scopedCount reduces the unscoped allowance from 1 to 0. The unscoped prompt becomes synthetic and disappears from scoring/task extraction. Combine scoped and unscoped completed counts before deduplicating against legacy counts.

  • [P1 blocking] Successful real-CLI verification remains undocumented — PR description, “Test Plan”. The Windows attempt exits 1 with UNVERIFIABLE; it is not a successful end-to-end record. The Code Review Rules item requiring real-CLI verification for runtime changes remains unmet. Record one passing representative run in a supported environment; referencing CI coverage alone does not supply that record.

Resolved: both earlier code findings—legacy/scoped double consumption and fallback when response turn metadata is absent—are fixed in the current diff.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Successful real-CLI verification remains undocumented — PR description, “Test Plan”. The Windows attempt exits 1 with UNVERIFIABLE, so it does not satisfy the Code Review Rules requirement for an end-to-end / real-CLI verification record when runtime behavior changes. Record one passing representative run in a supported POSIX world; citing CI coverage alone is insufficient.

Resolved in the current diff: legacy/scoped double consumption, fallback when response turn metadata is absent, and preservation of separate scoped and unscoped completed-event allowances.

No additional confident code findings.

@XY-code1

Copy link
Copy Markdown
Collaborator Author

Addressed both remaining blockers in c7eb177:

  • completed-event accounting now combines scoped and unscoped counts before deduplicating against legacy counts, then reserves only the scoped share; the new two-prompt “Continue.” regression passes alongside the earlier cases (6/6 focused tests);
  • the Test Plan now contains a successful real-CLI record from the packed CLI in a Debian Linux verify world. teamai session show --source codex preserved both genuine identical prompts, and the ledger ended CLEAN.

Typecheck, targeted type-aware lint, and git diff --check also pass.

@XY-code1

Copy link
Copy Markdown
Collaborator Author

CI triage for c7eb177: the failing fork-safe E2E shard reports an outdated unsupported-MR-URL assertion (the CLI now also lists GitCode) and a source manifest isolation case where the second removal exits 1. The same two test files are flagged in the main CI run. The aggregate E2E check also fails because the shard failed.

#2114 already updates both test files, so I am leaving those unrelated changes out of this Codex PR. Once the upstream fix lands, the next step is to update this branch from main and check the E2E result again.

@github-actions

Copy link
Copy Markdown

No confident findings in the current diff.

Resolved:

  • Legacy/scoped events no longer double-consume prompt allowances.
  • Responses without turn metadata can fall back to scoped text matching.
  • Separate scoped and unscoped completed prompts retain their allowances.
  • The PR description now documents a successful representative real-CLI run in an isolated Debian world, satisfying the testing requirement.

Review was read-only; no PR code was run, built, or installed.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants