Commit Graph

8 Commits

Author SHA1 Message Date
kavish-19 9fac73788b fix(codex): re-inject memory after compact and clear (#3880)
In Codex, memory is never re-injected after a context compaction. The
SessionStart hook that runs `hook codex context` matches only
"startup|resume", so after a manual /compact or an auto-compaction the
hook does not fire and the session continues with an empty context. A
long-running Codex session loses all injected memory at its first
compaction and never gets it back.

Codex emits four SessionStart sources, not two — SessionStartSource in
codex-rs/hooks/src/events/session_start.rs is Startup, Resume, Clear,
Compact. clear and compact both hand the model a fresh context, which is
exactly when the injection has to run. The Claude Code config already
matches "startup|clear|compact" for the same reason.

Add the two missing sources to the matcher. The hook command is
unchanged and does not branch on source, so it injects on compact and
clear exactly as it already does on startup and resume.

Closes #3862
2026-09-10 18:01:33 -07:00
Alex Newman fe9180c297 fix(codex): make startup context injection fast and bounded (#3789)
* fix(codex): simplify startup context injection

* fix(codex): bound cold worker startup

* fix(codex): cover supported cold starts
2026-08-28 21:19:20 -07:00
Alex Newman 7d3f1879eb fix(worker): single version oracle — never rank plugin cache dirs by mtime
The 2026-07-22 restart storm: claude-mem had four resolvers that ranked
plugin cache dirs by directory mtime (worker-utils
cacheWorkerScriptCandidates, the inline node L() and Codex Windows
resolvers in hook-shell-template, and the POSIX `ls -dt` hook resolver),
while the staleness detector compared the live worker against the
marketplace package.json. When Claude Code stamped the superseded
13.11.0 cache dir with .orphaned_at, its mtime became newest, so every
recycle respawned 13.11.0 while hooks running 13.12.0 kept demanding a
restart — 485 respawns in ~2 hours, each spawning SDK and Chroma
children, until the host exhausted its process table.

The fix is an invariant, not a mitigation: one deterministic version
oracle shared by detection and respawn.

- resolveWorkerScript() ranks candidates by version descending (numeric
  major.minor.patch, release ahead of prerelease at the same base,
  reverse-lexical tiebreak) and skips .orphaned_at-stamped dirs; stable
  sort keeps cache → marketplace → cwd precedence on ties.
- ensureWorkerRunning() resolves once and feeds the same result to both
  checkVersionMatch(port, expectedVersion) and the lazy-spawn script, so
  a mismatch can only ever resolve toward the version the respawn will
  actually produce — the loop is structurally impossible.
- checkVersionMatch now takes the caller's expected version;
  getInstalledPluginVersion (the second oracle) is deleted.
- All three generated bootstrap resolvers (mcp node launcher, Codex
  Windows launcher, POSIX hook prelude) embed the identical ordering;
  the POSIX variant uses a zero-padded sort key and balanced (pattern)
  case forms (unmatched parens are a parser error inside $(...)).
- scripts/build-hooks.js gains --write-shell-templates, the regeneration
  mode its hand-edit tripwire error message points at.
- Regression coverage: comparator/selection unit tests plus a functional
  shell-matrix test that rebuilds the exact storm layout (orphaned old
  dir with newest mtime) and asserts the new version wins.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-22 22:30:35 -07:00
Alex Newman 2282220d1b fix(codex): add Windows hook overrides
(cherry picked from commit fe5e0120e8)
2026-07-05 15:06:35 -07:00
Alex Newman 16b2c72d57 fix(codex): repair startup hooks and stale mcp config 2026-06-24 16:32:33 -07:00
Alex Newman aedfe5b6d9 batch: dead migration-system removal + Windows EACCES pipe fix (#2845 #2725) (#2865)
* fix(hooks): drop pipe `break` that triggers EACCES on Windows/Cygwin

Hook/MCP plugin-root resolution piped a candidate list into a `while`
loop that `break`s on the first match:

    _P=$({ printf ...; ls -dt ...; printf ...; } | while read _R; do
       ... && { printf '%s\n' "$_Q"; break; }; done)

On Cygwin/MSYS shells (Git-Bash on Windows) the early `break` closes
the pipe's read end while the producer subshell is still writing the
remaining candidate lines. The next `printf`/`ls` then writes to a
broken pipe, which Cygwin surfaces as EACCES rather than EPIPE:

    printf: write error: Permission denied

...failing the hook. It is a pipe-lifetime race, not a path/username
encoding problem — it reproduces 40/40 once CLAUDE_PLUGIN_ROOT is set
(so the first candidate matches and `break` fires immediately, leaving
the most pending producer output).

Fix: don't `break`. Drain every candidate (only a handful) and print
the FIRST match exactly once via a `_F` guard, so the producer always
completes and no broken-pipe write happens. First match still wins, so
the contractual fallback ORDER is unchanged. The change is POSIX-clean
(no bashisms), so the `mcp` host's `sh -c` launcher is fixed too.

Patched the single source of truth (src/build/hook-shell-template.ts)
and regenerated the three host-managed files; verified all 15 command
strings still match the canonical generator byte-for-byte, and that the
regenerated commands produce 0/30 EACCES under both bash and sh with
CLAUDE_PLUGIN_ROOT set.

Fixes #2707. Related #2709.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(hooks): reset _F before the resolution loop

Review follow-up. The first-match guard reads `[ -z "$_F" ]` before _F
is ever assigned. The `while` loop runs in the pipe's subshell, which
inherits the parent shell's variables, so an inherited non-empty `_F`
(e.g. an exported var in the host environment) would make the guard
false on every iteration: nothing prints, `_P` stays empty, and the
hook exits "not found".

Prefix the command substitution with `_F=;` so the guard always starts
from a known-empty state. Regenerated the three host-managed files;
canonical generator check still matches byte-for-byte, and the command
resolves correctly under bash and sh even with `_F=1` exported.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore(sqlite): remove dead legacy migration system (migrations.ts)

migration001..010 + the migrations[] array were orphaned by the #534
MigrationRunner refactor — zero importers. Build + full test suite
show no regression (11 pre-existing flaky fails identical on main).

* build: regenerate bundles + restore canonical hook JSONs for template fix

---------

Co-authored-by: Steven Moreno <steven.moreno@kpginc.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: wangchenguang <darion.yaphets@gmail.com>
2026-06-09 15:08:22 -07:00
Alex Newman 65f2fd8cdd fix: harden startup and schema repair contracts
Reliability patch covering startup path resolution, install marker compatibility, export CLI request contracts, schema repair safety, hard-stop retry-loop handling, and the PR babysit status helper.
2026-05-06 18:29:26 -07:00
Alex Newman 56db06811e Add native Codex hooks integration (#2319)
* Add native Codex hooks integration

* Address Codex review feedback

* Use durable Codex marketplace root

* Address Codex file context review feedback

* Harden Codex installer review paths

* Report Codex legacy cleanup failures

* fix: keep MCP manifests in marketplace sync

* fix: bundle zod in MCP server

* fix: warn on Codex legacy cleanup failure

* Fix hook observation readiness timeouts

* Address Codex hook review notes

* Tighten Codex MCP file context matching

* Resolve final Codex review nits

* Add Codex marketplace version guidance

* Reset worker failure counter on API fallback

* Fix Codex cat flag file extraction
2026-05-06 01:55:27 -07:00