Skip to content

fix(agent): record ended_early when a clean exit leaves the skeleton behind - #668

Open
yzxcj797 wants to merge 2 commits into
langchain-ai:mainfrom
yzxcj797:fix/ended-early-status-653
Open

fix(agent): record ended_early when a clean exit leaves the skeleton behind#668
yzxcj797 wants to merge 2 commits into
langchain-ai:mainfrom
yzxcj797:fix/ended-early-status-653

Conversation

@yzxcj797

Copy link
Copy Markdown

Summary

Fixes #653.

.last-update.json recorded status: "complete" whenever the agent's final turn ended without an error — including runs that ended on a plan, a "would you like me to continue?", or an announced-but-not-performed cleanup. Anything keying on the status (resume logic, CI docs jobs, batch scripts, the --update no-op check) then treated a mostly-unwritten wiki as finished and skipped it.

What this does

Gates complete on the one piece of verifiable state the run controls. The agent is instructed to delete _skeleton.md once every wiki file has been written, so on a clean exit a leftover skeleton means the run ended before finishing:

  • New UpdateRunStatus value "ended_early" (distinct from interrupted, which keeps its stream/owner-failure meaning).
  • The success path checks hasLeftoverSkeletonFile(cwd, outputMode) and records ended_early instead of complete when it's present — catching the "announced deleting _skeleton.md without doing it" case regardless of what the final message claimed.
  • getUpdateNoopStatus treats ended_early like interrupted: never skip, with its own reason ("previous run ended before finishing the wiki").
  • readLastUpdate preserves the new value; metadata written before the status field existed still reads as complete, so upgrades don't force spurious re-runs.
  • The gate emits a visible warning (run event + stderr, the same dual-channel pattern as the model-mismatch warning) naming the leftover file, so batch operators see why the wiki isn't marked complete without opening the JSON.

Tests

  • test/agent/skeleton-status.test.ts: skeleton detection in both output modes (repository openwiki/_skeleton.md, local-wiki root), negative case, and a metadata write/read round-trip for ended_early.
  • test/agent/update-noop.test.ts: the no-op check does not skip after an ended_early run.

OpenRouter's platform-side 429s (free-models-per-min) carry no
Retry-After, which the LangChain AsyncCaller classifies as
non-retryable capacity and turns into an immediate abort, so
OPENWIKI_PROVIDER_RETRY_ATTEMPTS never applied and ~50s of agent work
was discarded on the first 429 (langchain-ai#664). langchain-ai#461's createProviderRetryFetch
only reaches ChatOpenAI-backed transports -- ChatOpenRouter has no
configuration option -- and its flat 1s fallback cannot ride out a
per-minute window anyway.

Retry in installOpenRouterDebugFetch, which already wraps every
OpenRouter chat-completions fetch:

- honour Retry-After (seconds or HTTP-date), then OpenRouter's
  X-RateLimit-Reset epoch (unix-ms, seconds-magnitude detection, small
  margin), then exponential backoff (1s doubling, 30s cap); header-
  derived waits are defensively capped at 5 min;
- spend the existing OPENWIKI_PROVIDER_RETRY_ATTEMPTS budget;
- only retry when the request is re-sendable (string/absent body, not a
  Request carrying a body) and propagate abort signals through the wait;
- keep the diagnostics contract: the final non-ok response is captured
  for attachOpenRouterDebugInfo, retries emit debug lines.
…behind

.last-update.json recorded status=complete whenever the agent's final
turn ended without an error, including runs that ended on a plan or a
question with most of the wiki unwritten. Consumers keying on the
status (resume logic, CI docs jobs, batch scripts, the update no-op
check) treated those as finished wikis and skipped them (langchain-ai#653).

Gate complete on the one verifiable state the run controls: the agent
is instructed to delete _skeleton.md once every wiki file is written,
so a leftover skeleton on a clean exit now records ended_early (new
UpdateRunStatus value; interrupted keeps its stream/owner-failure
meaning). The no-op check never skips after ended_early, old metadata
without a status field still reads as complete, and the gate emits a
visible warning naming the leftover file.
@changeset-bot

changeset-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 203f2f6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.last-update.json records status: "complete" when the agent exits without finishing

1 participant