teapot-coding-agent 0.37.142 → 0.37.143

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -656,17 +656,31 @@ export class Agent {
656
656
  /**
657
657
  * Everything in the session directory that the panel needs: goal, todo, workspace presence.
658
658
  *
659
- * Idempotent, so `init()` and `ensureReady()` can both ask without reading twice.
659
+ * Idempotent via the IN-FLIGHT PROMISE, not a boolean.
660
+ *
661
+ * The flag was set before the first `await`, so a second caller during the read got an already-"done" state and
662
+ * returned immediately — while the goal and todo had not been applied yet. MEASURED as a CI-only failure of
663
+ * `test/storage.test.ts` ("sibling-prefix ids", `kernel2.goal.text` was `""` right after `load()` while the session
664
+ * directory assertion right above it passed), and it is a contract violation rather than a flake: `load()` promises
665
+ * the session is ready, and the goal is part of the session.
666
+ *
667
+ * Sharing the promise means every caller waits for the SAME read — `ensureReady()` can still start it in the
668
+ * background (so a spawned child's "running" transition is not delayed, which is why it was deferred at all), and
669
+ * `load()` can wait for it without re-reading.
660
670
  */
661
- sessionStateLoaded = false;
662
- async loadSessionState() {
663
- if (this.sessionStateLoaded)
664
- return;
665
- this.sessionStateLoaded = true;
666
- await this.migrateMemoryToAgentScope();
667
- await this.migrateGoalFromWorkspace();
668
- this.goal = (await this.readGoalStore()) ?? this.goal;
669
- this.todo = await fs.readFile(this.todoFile, "utf8").catch(() => "");
671
+ sessionStatePromise;
672
+ loadSessionState() {
673
+ this.sessionStatePromise ??= (async () => {
674
+ await this.migrateMemoryToAgentScope();
675
+ await this.migrateGoalFromWorkspace();
676
+ this.goal = (await this.readGoalStore()) ?? this.goal;
677
+ this.todo = await fs.readFile(this.todoFile, "utf8").catch(() => "");
678
+ })().catch((err) => {
679
+ // a failed read must not poison the memo: the next caller may retry
680
+ this.sessionStatePromise = undefined;
681
+ throw err;
682
+ });
683
+ return this.sessionStatePromise;
670
684
  }
671
685
  ensureReady() {
672
686
  if (!this.readyPromise) {
@@ -699,6 +713,13 @@ export class Agent {
699
713
  }
700
714
  async load() {
701
715
  await this.ensureReady();
716
+ /**
717
+ * …and the session's own state, which `ensureReady()` starts but deliberately does not wait for.
718
+ *
719
+ * Without this, `load()` returned while the goal/todo read was still in flight: `snapshot()` and `goal` looked
720
+ * loaded, and a caller that read `agent.goal` straight afterwards got the empty initial value.
721
+ */
722
+ await this.loadSessionState();
702
723
  }
703
724
  async answerUnansweredRestoredCalls() {
704
725
  const seen = new Set();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.37.142",
3
+ "version": "0.37.143",
4
4
  "description": "A lightweight, always-on multi-agent harness for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",