Skip to content

Commit c7d8407

Browse files
authored
Merge pull request #3002 from lidge-jun/codex/promote-main-2360
[WRONG BRANCH] promote dev onto main for v2.36.0
2 parents fc4de77 + bb6a6fb commit c7d8407

537 files changed

Lines changed: 46302 additions & 2296 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/scripts/closed-pr-branch-cleanup.cjs‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@
1616
/** Branches that may never be deleted regardless of pull-request state. */
1717
const PROTECTED_BRANCHES = Object.freeze(["main", "dev", "preview", "gh-pages"]);
1818

19+
/** Branch namespaces explicitly reserved for disposable pull-request work. */
20+
const DISPOSABLE_BRANCH_PREFIXES = Object.freeze(["codex/", "ingw/"]);
21+
1922
/** Default grace period before a closed PR's head branch becomes eligible. */
2023
const DEFAULT_GRACE_DAYS = 14;
2124

2225
function normalizeBranchName(value) {
23-
return String(value || "").trim();
26+
// Git permits non-ASCII whitespace in ref names, while String#trim removes
27+
// it. Preserve API-provided branch identity byte-for-byte so two distinct
28+
// refs cannot collapse into one deletion candidate.
29+
return typeof value === "string" ? value : "";
2430
}
2531

2632
/**
@@ -59,6 +65,7 @@ const KEEP_REASONS = Object.freeze({
5965
CROSS_REPOSITORY: "cross-repository-head",
6066
MISSING_CLOSED_AT: "missing-closed-at",
6167
WITHIN_GRACE: "within-grace-period",
68+
OUTSIDE_DISPOSABLE_NAMESPACE: "outside-disposable-namespace",
6269
MOVED_SINCE_CLOSE: "branch-moved-since-close",
6370
UNKNOWN_HEAD_SHA: "unknown-head-sha",
6471
});
@@ -79,6 +86,11 @@ const KEEP_REASONS = Object.freeze({
7986
* contributor's repository and this token has no business there.
8087
* - A grace period after `closed_at` leaves room to reopen a PR that was
8188
* closed by mistake.
89+
* - Only branches under namespaces explicitly reserved for disposable pull-
90+
* request work are eligible. Pull-request history alone must not authorize
91+
* deletion of an unrelated persistent branch.
92+
* - Branch names are compared and emitted byte-for-byte. Normalizing Unicode
93+
* whitespace can merge distinct valid refs and delete the wrong branch.
8294
* - The branch must still POINT AT a commit one of those closed pull requests
8395
* had as its head. Matching by NAME alone deletes reused work: `codex/`-style
8496
* names get picked up again all the time, and a branch recreated for new work
@@ -178,6 +190,11 @@ function planClosedPrBranchDeletions({
178190
continue;
179191
}
180192

193+
if (!DISPOSABLE_BRANCH_PREFIXES.some((prefix) => branch.startsWith(prefix))) {
194+
keeps.push({ branch, reason: KEEP_REASONS.OUTSIDE_DISPOSABLE_NAMESPACE });
195+
continue;
196+
}
197+
181198
// The tip check, last because it is the most expensive claim to satisfy and
182199
// the cheaper rules above have already excluded most branches.
183200
//
@@ -219,6 +236,7 @@ function planClosedPrBranchDeletions({
219236

220237
module.exports = {
221238
DEFAULT_GRACE_DAYS,
239+
DISPOSABLE_BRANCH_PREFIXES,
222240
KEEP_REASONS,
223241
PROTECTED_BRANCHES,
224242
isProtectedBranch,

‎.github/scripts/closed-pr-branch-cleanup.test.cjs‎

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ const { describe, it } = require("node:test");
44
const assert = require("node:assert/strict");
55
const {
66
DEFAULT_GRACE_DAYS,
7+
DISPOSABLE_BRANCH_PREFIXES,
78
KEEP_REASONS,
89
isProtectedBranch,
910
planClosedPrBranchDeletions,
1011
} = require("./closed-pr-branch-cleanup.cjs");
1112

1213
const NOW = Date.parse("2026-08-26T00:00:00Z");
1314
const DAY = 24 * 60 * 60 * 1000;
15+
const HEAD_OID = "a".repeat(40);
16+
const OTHER_OID = "b".repeat(40);
17+
const NBSP = "\u00a0";
1418
const longAgo = new Date(NOW - 60 * DAY).toISOString();
1519

1620
function closedPr(overrides) {
@@ -20,6 +24,7 @@ function closedPr(overrides) {
2024
merged: false,
2125
isCrossRepository: false,
2226
headRefName: "codex/example",
27+
headRefOid: HEAD_OID,
2328
baseRefName: "dev",
2429
closedAt: longAgo,
2530
...overrides,
@@ -42,13 +47,17 @@ describe("isProtectedBranch", () => {
4247
}
4348
assert.equal(isProtectedBranch("codex/dev"), false);
4449
});
50+
51+
it("declares the disposable pull-request branch namespaces", () => {
52+
assert.deepEqual(DISPOSABLE_BRANCH_PREFIXES, ["codex/", "ingw/"]);
53+
});
4554
});
4655

4756
describe("planClosedPrBranchDeletions", () => {
4857
it("deletes a branch whose only pull request closed unmerged past the grace period", () => {
4958
const result = planClosedPrBranchDeletions({
5059
pullRequests: [closedPr({ number: 42, headRefName: "codex/stale" })],
51-
branches: ["codex/stale", "dev"],
60+
branches: [{ name: "codex/stale", oid: HEAD_OID }, "dev"],
5261
now: NOW,
5362
});
5463
assert.deepEqual(deletedBranches(result), ["codex/stale"]);
@@ -147,13 +156,58 @@ describe("planClosedPrBranchDeletions", () => {
147156
it("ignores branches that no pull request ever used", () => {
148157
const result = planClosedPrBranchDeletions({
149158
pullRequests: [closedPr({ number: 80, headRefName: "codex/known" })],
150-
branches: ["codex/known", "codex/never-a-pr"],
159+
branches: [
160+
{ name: "codex/known", oid: HEAD_OID },
161+
{ name: "codex/never-a-pr", oid: HEAD_OID },
162+
],
151163
now: NOW,
152164
});
153165
assert.deepEqual(deletedBranches(result), ["codex/known"]);
154166
assert.equal(keepReason(result, "codex/never-a-pr"), null);
155167
});
156168

169+
it("keeps a persistent branch even when a closed pull request still matches its tip", () => {
170+
const branch = "release/maintenance";
171+
const result = planClosedPrBranchDeletions({
172+
pullRequests: [closedPr({ number: 85, headRefName: branch })],
173+
branches: [{ name: branch, oid: HEAD_OID }],
174+
now: NOW,
175+
});
176+
assert.deepEqual(deletedBranches(result), []);
177+
assert.equal(
178+
keepReason(result, branch),
179+
KEEP_REASONS.OUTSIDE_DISPOSABLE_NAMESPACE,
180+
);
181+
});
182+
183+
it("preserves Unicode whitespace so distinct valid refs never collapse", () => {
184+
const disposable = `codex/live${NBSP}`;
185+
const result = planClosedPrBranchDeletions({
186+
pullRequests: [closedPr({ number: 86, headRefName: disposable })],
187+
branches: [
188+
{ name: "codex/live", oid: OTHER_OID },
189+
{ name: disposable, oid: HEAD_OID },
190+
],
191+
now: NOW,
192+
});
193+
assert.deepEqual(result.deletions, [{ branch: disposable, pullRequests: [86] }]);
194+
assert.equal(keepReason(result, "codex/live"), null);
195+
});
196+
197+
it("does not trim leading Unicode whitespace into a disposable namespace", () => {
198+
const branch = `${NBSP}codex/persistent`;
199+
const result = planClosedPrBranchDeletions({
200+
pullRequests: [closedPr({ number: 87, headRefName: branch })],
201+
branches: [{ name: branch, oid: HEAD_OID }],
202+
now: NOW,
203+
});
204+
assert.deepEqual(deletedBranches(result), []);
205+
assert.equal(
206+
keepReason(result, branch),
207+
KEEP_REASONS.OUTSIDE_DISPOSABLE_NAMESPACE,
208+
);
209+
});
210+
157211
it("only plans deletions for branches that still exist", () => {
158212
const result = planClosedPrBranchDeletions({
159213
pullRequests: [closedPr({ number: 90, headRefName: "codex/already-gone" })],

‎AGENTS.md‎

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ it binds you regardless of which mechanism is within reach.
171171
```bash
172172
bun install
173173
bun run typecheck # bun x tsc --noEmit (strict)
174-
bun run test # full tests/ suite
174+
bun run test:changed # import-graph tests against the resolved `dev` merge base
175+
bun run test # full tests/ suite (PR-ready / explicit ask only)
175176
bun run lint:gui # GUI eslint
176177
bun run privacy:scan # credential/privacy scan used by CI
177178
bun run build:gui # Vite GUI build
@@ -191,17 +192,55 @@ also if the hand-written pages name a command the registry does not have. That s
191192
hypothetical: it caught a documented `ocx request-history` that never existed.
192193

193194
During implementation, use the smallest focused checks that directly cover the
194-
changed subsystem. Do not run repository-wide `bun run typecheck` or
195-
`bun run test` for a scoped change unless the change affects shared runtime,
196-
routing, config, server behavior, a focused result is failed or ambiguous, or
197-
the user explicitly asks for full validation.
195+
changed subsystem. Prefer `bun test tests/<name>.test.ts` for a known file, or
196+
`bun run test:changed` when the touch set is broader than one file. Do **not**
197+
run repository-wide `bun run test` or a bare `bun test` with no file arguments
198+
for a scoped change by default. `bun run test:changed` follows Bun's parsed module graph: it
199+
selects test files that import changed modules, but it cannot see dependencies
200+
expressed through subprocesses, source files read as data, or golden/derived
201+
files. Run the relevant focused tests explicitly for those paths; if no reliable
202+
focused set covers them, the full suite is required even for a scoped change.
203+
That indirect-dependency case is the explicit exception to the scoped-change
204+
default. The full suite is ~850 files, so otherwise reserve it for a failed or
205+
ambiguous focused result, an explicit user request, or the PR-ready gate below.
198206

199207
Before creating or updating a non-trivial PR as review-ready, or before
200208
approving such a PR, run `bun run typecheck` and `bun run test`. CI runs these
201209
on Linux, Windows, and macOS.
202210

203211
Do not rerun passing checks on unchanged code merely for additional confidence.
204212

213+
## Minimal containers and agent sandboxes
214+
215+
Fresh dev containers and agent sandboxes (Cursor Cloud, devcontainers, CI
216+
images) often ship Node but not Bun. Install it first:
217+
218+
```bash
219+
curl -fsSL https://bun.sh/install | bash # installs ~/.bun/bin/bun
220+
export PATH="$HOME/.bun/bin:$PATH"
221+
bun install && (cd gui && bun install)
222+
```
223+
224+
Run the proxy with `bun run src/cli/index.ts start --port <port>`. `/healthz`
225+
reports status, `/` serves the dashboard, and the management API requires the
226+
admin token the server writes to `$OPENCODEX_HOME/admin-api-token` at startup.
227+
228+
`bun run test` has five known environment-only failures in such containers.
229+
They are not regressions; do not re-investigate them:
230+
231+
- `service diagnostics > status summary exposes the service log path`,
232+
`CLI subcommand help > status prints diagnostics without starting the proxy`,
233+
and `CLI subcommand help > invalid service and codex-shim usage include
234+
remove alias` require a running systemd init; in a container PID 1 is
235+
typically `tini` or another minimal init, so service commands report
236+
"systemd not found".
237+
- `package tree integrity > an in-place rewrite of the same byte length is
238+
still a replacement` and `Codex Log Guard inspection > repeat inspection is
239+
memoized and invalidated by a write` rely on filesystem mtime granularity
240+
that some container filesystems do not provide.
241+
242+
Everything else passes (15480 pass / 16 skip / 5 fail as of 2.35.0).
243+
205244
## Issues and pull requests (agents)
206245

207246
Agent-created issues and PRs must use the repository templates. The gates
@@ -295,8 +334,9 @@ reviewers (Codex, CodeRabbit).
295334
assumptions about a compile step, or code paths that break `bun run
296335
typecheck` / `bun run test`.
297336
- **Tests:** behavior changes in `src/` need a focused regression test near
298-
the existing tests for that subsystem. Shared routing, adapter, config, or
299-
server changes need the full suite green.
337+
the existing tests for that subsystem. During implementation, run the relevant
338+
focused files and use `bun run test:changed` for import-connected coverage as
339+
described above; the full suite is the PR-ready gate.
300340
- **Docs sync:** user-facing behavior changes should update `docs-site/` (and
301341
keep translated locales from contradicting the English source).
302342
- **Privacy:** `bun run privacy:scan` must stay green; never introduce logging

‎assets/pr2950-capacity-expiry.png‎

76 KB
Loading

devlog/_plan/260828_kiro_turn_termination/000_research.md renamed to devlog/_fin/260828_kiro_turn_termination/000_research.md

File renamed without changes.

devlog/_plan/260828_kiro_turn_termination/010_wp1_terminal_boundary.md renamed to devlog/_fin/260828_kiro_turn_termination/010_wp1_terminal_boundary.md

File renamed without changes.

devlog/_plan/260828_kiro_turn_termination/011_audit_round1.md renamed to devlog/_fin/260828_kiro_turn_termination/011_audit_round1.md

File renamed without changes.

devlog/_plan/260828_kiro_turn_termination/012_audit_round2.md renamed to devlog/_fin/260828_kiro_turn_termination/012_audit_round2.md

File renamed without changes.

devlog/_plan/260828_kiro_turn_termination/020_wp2_duplicate_answer.md renamed to devlog/_fin/260828_kiro_turn_termination/020_wp2_duplicate_answer.md

File renamed without changes.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# wp2 audit round 3 — the outer drain must not learn about completions
2+
3+
Reviewer: independent explorer lane, read-only, HEAD `a43e4cda`.
4+
Verdict: **FAIL** on the plan as written in `020_wp2_duplicate_answer.md`.
5+
This document records the finding and the corrected design.
6+
7+
## What the reviewer accepted
8+
9+
- Consuming the retained collection on a valid completion IS sufficient to remove
10+
the user-visible duplicate. Required-mode text is held only in `deferred`
11+
(`src/adapters/kiro.ts:1174-1179`, `:1207`), fallback text only in
12+
`fallbackEvents` (`:1202-1205`), and a valid completion never live-flushes that
13+
run because a completion alongside a real tool call is already a protocol error
14+
(`:1260-1261`). With the commentary `text_delta` gone, `src/bridge.ts` never
15+
splits the message.
16+
- There is **no third emitter**. `:1523` builds a new event from
17+
`completionAnswer`; it does not read `deferred`. The early-loop yields at
18+
`:1398` and `:1418` only flush `deferred` when a real tool starts (`:1175`).
19+
- Dropping `text_delta` while keeping non-text retained events loses nothing
20+
load-bearing on this path. Tool events never sit in the collection — they splice
21+
live and forbid a valid completion.
22+
- `releaseEvent` is idempotent via its `eventBytes` map guard (`:808-810`), so a
23+
double release cannot double-credit the budget.
24+
25+
## The blocker
26+
27+
`020`'s option 1 says to consume the collection at BOTH readers — the inner flush
28+
and the outer drain in `parseKiroAttempt` (`:996-1001`). The reviewer showed the
29+
second half is wrong:
30+
31+
> `996-1001` is also the leftover flush for early `terminal` returns that never
32+
> hit `1468` (`1405-1413`). Dropping `text_delta` there without a completion flag
33+
> hides the only commentary.
34+
35+
That outer drain is the release path for stream, protocol, and provider failures —
36+
the row `020`'s own table requires to stay intact. A turn that fails after emitting
37+
progress prose would lose that prose entirely, which is a worse defect than the
38+
duplicate: the user would see an error with no indication of what the model had
39+
been doing.
40+
41+
## Corrected design
42+
43+
The inner site is the only consumer, and it leaves the collection **empty**:
44+
45+
1. `src/adapters/kiro.ts:1468`, `mode === "required"`: when
46+
`completionAnswer !== undefined`, splice the collection and consume it — drop
47+
each `text_delta` after releasing its retention, yield every non-text event and
48+
release it. When there is no completion answer, flush exactly as today.
49+
2. `:1474`, `mode === "text_fallback"`: this branch is **already** gated on
50+
`completionAnswer !== undefined`, so the same consume applies there and nowhere
51+
else in that mode.
52+
3. `:996-1001`, the outer drain: **unchanged**. Because step 1 splices, there is
53+
nothing left for it to emit on the completion path, and it keeps its full
54+
flush behaviour for every early-terminal path.
55+
56+
The correction is that suppression is expressed by emptying the collection at the
57+
one site that knows a completion arrived — not by teaching a second,
58+
failure-serving reader to discard text.
59+
60+
Untouched, per `020`'s release table: the `sawRealTool` flush (`:1483`), the
61+
plain-text promotion (`:1490-1498`), and the empty/reasoning-only fallback
62+
(`:1505`).
63+
64+
## Budget note
65+
66+
The reviewer's condition for a leak is "splice, skip `releaseEvent`, and skip
67+
`releaseAll`". The consume path releases every event it drops, and
68+
`releaseRetained`/`releaseAll` still runs for the `trackReplacement` remainder
69+
(`:801-803`), which is not tracked in `eventBytes`. A test asserts the budget
70+
returns to baseline.
71+

0 commit comments

Comments
 (0)