Skip to content

fix(codex-memory-plugin): stop PostToolUse usage hook from injecting additionalContext - #5738

Merged
ZaynJarvis merged 2 commits into
volcengine:mainfrom
t0saki:fix/codex-usage-hint-between-tool-outputs
Oct 8, 2026
Merged

ZaynJarvis merged 2 commits into
volcengine:mainfrom
t0saki:fix/codex-usage-hint-between-tool-outputs

Conversation

@t0saki

@t0saki t0saki commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The daily integration case journey-g01-a-codex-cli-to-codex-cli-model-observed failed two runs in a row: the model provider returned 400 InvalidParameter, the turn ended with turn.failed, and codex exited 1. The rejected request had a developer message sitting between two function_call_output items that belonged to the same tool-call batch.

Root cause chain:

  • feat(codex-plugin): add built-in OpenViking usage summaries #5699 (25ad26a, "feat(codex-plugin): add built-in OpenViking usage summaries") registered scripts/usage/track-lookup.mjs as a PostToolUse hook (matcher Bash|(?:functions\.)?exec|mcp__.*openviking.*__.*). In desktop output mode it returned hookSpecificOutput.additionalContext carrying the current-turn usage footer from answerContext(...).
  • Codex injects PostToolUse additionalContext as a developer message immediately after that tool's output.
  • When one model response issues several tool calls in parallel, the developer message for the first call lands before the remaining function_call_output items of the same batch.
  • Strict Responses-API providers require all outputs of a call batch to be contiguous, so they reject the request with 400 InvalidParameter, which fails the turn.

Fix: track-lookup.mjs now only records the lookup and always returns {}. Lookup data still reaches the user through the existing Stop hook (report.mjs) in terminal mode, and the desktop footer is still supplied by the UserPromptSubmit recall hook, which runs before any tool call and so cannot split a tool-output batch. The trade-off is that the desktop model-rendered footer no longer includes explicit lookups made during the turn; terminal reports are unchanged.

Second change: OV-Usage was configurable only through OPENVIKING_USAGE_VIEW / OPENVIKING_USAGE_OUTPUT. Both are now shared knobs (usageView, usageOutput) in config-schema.mjs, so they can also be set in ovcli.conf's plugin / plugin.codex section, a workspace config file (usage.view / usage.output), or ov.conf's legacy codex section. The env vars still win, the defaults (summary, auto) are unchanged, and the accepted spellings (off/false/0/disabled, expanded/full/details, case-insensitive) are unchanged. The usage hooks read the value from the plugin's existing loadConfig(); auto-recall passes its already-loaded config.

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

Regression from #5699.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • scripts/usage/track-lookup.mjs: stop returning additionalContext from the PostToolUse hook; drop the per-call transcript recall read and footer rendering that only fed it.
  • scripts/marketplace.test.mjs: assert the lookup hook returns {} in both desktop and terminal modes, and verify lookup attribution through the Stop report instead of the hook output.
  • README.md: describe the lookup hook as record-only and explain why it never returns additionalContext.
  • Bump the Codex plugin to 0.11.4.
  • memory-plugin-shared/lib/config-schema.mjs: add usageView (env OPENVIKING_USAGE_VIEW, workspace usage.view) and usageOutput (env OPENVIKING_USAGE_OUTPUT, workspace usage.output); synced vendored copies; examples/schemas/workspace-config-v1.json gains a usage section.
  • scripts/usage/{settings,display,report,track-lookup}.mjs, scripts/auto-recall.mjs: read the resolved config instead of raw process.env.
  • scripts/config.test.mjs: config file disables usage, workspace sets output, env overrides the file.
  • Docs: Codex README OV-Usage and workspace sections, doctor reference, shared README, docs/{en,zh}/configuration/02-client.md workspace key table.
  • Because the shared library changed, bump every plugin that ships it: claude-code 0.7.5, agent-hook 0.5.13, opencode 0.5.7, dsh 0.5.19, pi 0.4.12.

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

node --test examples/codex-memory-plugin/scripts/*.test.mjs: 189 passed, 0 failed. examples/memory-plugin-shared/*.test.mjs: 551 passed. claude-code 53, agent-hook 73, opencode 51, dsh 95 passed (1 skipped), all 0 failed; check-plugin-version-bumps.sh origin/main and dsh npm run check:version pass. pi: 281 passed, 4 takeover tests fail identically on origin/main (pre-existing).

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

N/A

Additional Notes

Not yet re-run against the integration case itself; the fix removes the only PostToolUse output this plugin produces.

…additionalContext

Codex inserts PostToolUse additionalContext as a developer message right
after the tool output. With parallel tool calls this lands between
function_call_outputs of one batch, which strict Responses-API providers
reject with 400 InvalidParameter. The lookup hook now only records
lookups; the Stop hook and the recall footer keep reporting usage.
…files

Declare usageView (OPENVIKING_USAGE_VIEW) and usageOutput
(OPENVIKING_USAGE_OUTPUT) as shared knobs so the OV-Usage footer can be
configured in ovcli.conf's plugin / plugin.codex section, the workspace
config (usage.view / usage.output), or ov.conf's codex section. The env
vars still win and the defaults are unchanged.

Bump every plugin that ships the shared config schema.
@t0saki
t0saki marked this pull request as ready for review October 8, 2026 07:01
Copilot AI balanced review requested due to automatic review settings October 8, 2026 07:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants