Skip to content

feat(core): make path-local instruction discovery durable#35497

Open
kitlangton wants to merge 1 commit into
v2from
instruction-rename
Open

feat(core): make path-local instruction discovery durable#35497
kitlangton wants to merge 1 commit into
v2from
instruction-rename

Conversation

@kitlangton

@kitlangton kitlangton commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Stacked on #35583 (rename). This PR contains only the schema/event additions and the discovery redesign.

Why

Discovered subdirectory AGENTS.md files were injected as synthetic history messages. Synthetic messages are just history: compaction summarizes them away, the model silently loses authoritative path-local conventions, and nothing can restate them — the baseline never contained them. The in-memory dedup ledger also reset on Location layer restarts.

What changes

One new table + one new event; everything else follows from them.

  • instruction_file records which path-local AGENTS.md files a session has discovered: (session_id, path) PK, content (discovery snapshot, fallback only), message_seq (owning assistant message; drives fork copy and revert deletion), discovered_seq + position (durable order). Added by its own append-only migration.
  • session.instructions.discovered is the durable fact; the projector folds it into instruction_file, applying it only when the session's directory/workspace still matches the recorded Location.
  • InstructionDiscovery absorbs SessionInstructions (deleted): discovered files join the core/instructions source, so completed compaction rebaselines restate them instead of summarizing them away.
  • Live re-observation: every step re-reads ambient and discovered files from disk; the stored content stands in only when a file becomes unreadable. Mid-session edits reach the model.
  • Per-file delta updates via Instructions.diffByKey: added files render as Instructions from: <path>, edits as per-file supersessions, removals as one line. Full-set restatement survives only for pure reorderings (previously every discovery re-sent the entire accumulated set — O(n²) tokens).
  • Lifecycle: fork copies rows within the inherited transcript, committed revert deletes rows past the boundary, session move/delete clears them so the destination rebuilds a complete baseline.

Compatibility

  • Previously emitted synthetic instruction messages remain historical session history; the migration does not infer structured files from old free-form text.
  • session.instructions.discovered joins the public event manifest; generated clients and SDK types are regenerated.

Verification

  • bun typecheck clean in core, protocol, server, client, codemode, sdk-next, schema.
  • Core suites green: discovery (ambient + durable, live-read, delta narration), runner (chronological update admission, no synthetic emission), projector (fork/revert/move handling), migrations (bun script/migration.ts --check passes), events, tool-read; codemode, sdk-next, schema manifest green.

@kitlangton kitlangton force-pushed the instruction-rename branch 2 times, most recently from c00ae67 to cda08a7 Compare July 6, 2026 18:24
@kitlangton kitlangton changed the title refactor(core): rename system context to instructions feat(core): make path-local instruction discovery durable Jul 6, 2026
@kitlangton kitlangton changed the base branch from v2 to instruction-rename-only July 6, 2026 18:25
Base automatically changed from instruction-rename-only to v2 July 6, 2026 18:29
Replace synthetic-message instruction injection with a durable
discovery projection so discovered AGENTS.md files survive compaction,
forks, reverts, and restarts.

- Add the instruction_file table and the durable
  session.instructions.discovered event; projection stores each
  discovered path and content with its owning assistant-message
  boundary and durable discovery order.
- Fold discovered files into the core/instructions source through
  InstructionDiscovery, absorbing SessionInstructions. Completed
  compaction rebaselines restate discovered instructions instead of
  summarizing them away.
- Re-read discovered files live at each observation so mid-session
  edits reach the model; the frozen discovery content stands in only
  when a file becomes unreadable.
- Narrate instruction file changes as per-file deltas via diffByKey,
  restating the full set only for pure reorderings.
- Fork copies discoveries within the inherited transcript, committed
  revert removes discoveries past the revert boundary, and Session
  movement clears them so the destination initializes a complete
  baseline.
@opencode-agent

opencode-agent Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Audit hygiene: #35583 is merged, so “Stacked on #35583” is stale. This PR is now the active implementation for #34341 (renamed to durable Instructions) and should link that tracker directly. The branch currently conflicts with v2, so it also needs rebase/conflict resolution before review.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant