Skip to content

[WRONG BRANCH] fix(responses): restrict encrypted task recovery to NEW_TASK envelopes - #483

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-mid-thread-recovery-issue
Draft

[WRONG BRANCH] fix(responses): restrict encrypted task recovery to NEW_TASK envelopes#483
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-mid-thread-recovery-issue

Conversation

@luvs01

@luvs01 luvs01 commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Restore the security invariant that MESSAGE envelopes are detection-only and must fail closed, preventing the recovery path from turning MESSAGE ciphertext into a plaintext oracle for routed providers.
  • Preserve the functional fix for mid-thread NEW_TASK recovery so legitimate mid-thread NEW_TASK ciphertext can still be recovered and reused.

Description

  • Constrain envelope parsing and recognition to NEW_TASK only by narrowing the AgentEnvelope.messageType and ROUTING_HEADER in src/server/responses/agent-task-recovery.ts so findEnvelope will not accept MESSAGE for recovery.
  • Keep the existing recovery, replay, and discard logic for NEW_TASK envelopes intact so mid-thread NEW_TASK recovery behavior and cache reuse remain available.
  • Update and add focused tests in tests/server/agent-task-recovery.test.ts to remove MESSAGE-based recovery expectations, and to assert that MESSAGE envelopes are rejected with unsupported_envelope and never trigger recovery I/O or cache restoration.

Testing

  • Ran the focused suite node_modules/.bin/bun test tests/server/agent-task-recovery.test.ts and all tests passed (59 pass, 0 fail).
  • Ran type checking with bun run typecheck which succeeded.
  • Ran privacy validation with bun run privacy:scan which reported Privacy scan passed.
  • Ran the full bun run test for broader context, which surfaced unrelated environment/parallel-runner failures in other suites; the focused recovery tests and typecheck above were green and validate the security regression fix.

Codex Task

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-11T12:13:26.025795Z bdbdaf3 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the bug Something isn't working label Sep 11, 2026
@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 87ea5f12-6159-41ca-b698-1220f6f74eea


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot changed the title fix(responses): restrict encrypted task recovery to NEW_TASK envelopes [WRONG BRANCH] fix(responses): restrict encrypted task recovery to NEW_TASK envelopes Sep 11, 2026
@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions
github-actions Bot marked this pull request as draft September 11, 2026 12:09

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bdbdaf330a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

const ROUTING_HEADER = /(?:^|\n)Message Type\s*:\s*(NEW_TASK|MESSAGE)\s*\nTask name\s*:\s*(\S+)\s*\nSender\s*:\s*(\S+)\s*\nPayload\s*:\s*(?:\n|$)/;
const ROUTING_HEADER = /(?:^|\n)Message Type\s*:\s*(NEW_TASK)\s*\nTask name\s*:\s*(\S+)\s*\nSender\s*:\s*(\S+)\s*\nPayload\s*:\s*(?:\n|$)/;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject MESSAGE headers rather than making them invisible

When an agent_message contains a MESSAGE routing-header part followed by a valid NEW_TASK routing-header part and ciphertext, this narrowed regex ignores the MESSAGE part, accepts the NEW_TASK part, and sends the ciphertext through recovery; previously both headers matched and the duplicate-header check rejected the input. A MESSAGE ciphertext can therefore be relabeled by adding a NEW_TASK sibling, bypassing the intended fail-closed boundary. Keep header recognition broad enough to detect both types, then explicitly admit only a sole NEW_TASK envelope.

AGENTS.md reference: AGENTS.md:L357-L363

Useful? React with 👍 / 👎.

expect(fetches).toBe(1);
});

test("MESSAGE envelopes fail closed without recovery or cache restoration", async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update every test that still requires MESSAGE recovery

This new fail-closed expectation contradicts five unchanged cases in tests/server/server-agent-task-recovery-replay.test.ts, including “MESSAGE recovery reaches the provider,” the MESSAGE cache and mixed-history cases, the handler recovery case, and the MESSAGE-tail case at lines 184-217, 249-348, and 416-427. Those tests still expect recovery to return true or the handler to return HTTP 200, whereas this change now returns unsupported_envelope/HTTP 400, so the repository-wide test gate will fail until those scenarios are updated to the new contract.

AGENTS.md reference: AGENTS.md:L367-L370

Useful? React with 👍 / 👎.

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

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant